Reputation: 4080
Mocha can't seem to match any patterns for some reason.
mocha -g MyClass
displays 0 passings (0ms)
, when I actually have several tests that can be run and passed if I run a single test script.
mocha test/my/test.js
yields 4 passing (10ms)
.
In test.js
, I have
describe ('MyClass', function () {
describe ('someMethod()', function () {
it ('Should be...', function () {
....
})
...
})
})
Any idea what I'm doing wrong? Using mocha 3.5.0.
Upvotes: 7
Views: 2765
Reputation: 26973
Another possible cause of Mocha apparently not finding specific tests that you're telling it to run with the --grep
or -g
option is if there are one or more other tests in your files that are defined with .only( ... )
.
If Mocha sees any such .only
tests, it won't run any other tests, even if your --grep
argument doesn't include the .only
test(s).
See: https://mochajs.org/#exclusive-tests
Upvotes: 0
Reputation: 151391
When you do mocha test/my/test.js
Mocha has no trouble finding the test because you give a full path to the file. When you do mocha -g MyClass
, Mocha has to find the file by itself. It looks in test
, and your test file is located under it. So far so good, but by default Mocha won't go into subdirectories of test
. So you have to do mocha -g MyClass --recursive
.
Upvotes: 5