I’m trying to get Mocha (browser-version, not Node) running inside my (Require.js) environment, but I’m running in to a strange issue.
If I do:
<script src="require.js" data-main='mochaTestMain.js'></script>
and then do the following in mochaTestMain.js:
require(['someFile'], function() {
describe('foo', function() {
it('foo', function() {
chai.expect(false).to.equal(true)
});
});
});
my “foo” spec results show up. However if I put that exact same test inside someFile.js (inside a define statement), the test doesn’t show up; it’s like Mocha was never even aware that it existed. If I add a console.log inside the describe, it shows up, but if I add one inside the it it doesn’t.
Does anyone have any suggestions as to what I can do to get Mocha to recognize tests defined in modules?
I don’t see where you call “mocha.run()” If it runs before the above tests, that may be one reason.
You can gain control over the timing of things by yanking the logic out of async threads into in-line flow:
contents of someTestFile.js:
contents of mochaTestMain.js: