I use Mocha to test my JavaScript stuff. My test file contains 5 tests. Is that possible to run a specific test (or set of tests) rather than all the tests in the file?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
Hi above solutions didn't work for me. The other way of running a single test is
This helps to run a test case from a single file and with specific name.
run single test –by filename–
Actually, one can also run a single mocha test by filename (not just by „it()-string-grepping“) if you remove the glob pattern (e.g.
./test/**/*.spec.js
) from your mocha.opts, respectively create a copy, without:Here's my mocha.single.opts (it's only different in missing the aforementioned glob line)
Background: While you can override the various switches from the opts-File (starting with
--
) you can't override the glob. That link also has some explanations.Hint: if
node_modules/.bin/mocha
confuses you, to use the local package mocha. You can also write justmocha
, if you have it installed globally.And if you want the comforts of
package.json
: Still: remove the**/*
-ish glob from yourmocha.opts
, insert them here, for the all-testing, leave them away for the single testing:usage:
respectively
(mind the
--
!)