How does testing framework mocha knows, which source file I am testing?

210 views Asked by At

talking about --> http://mochajs.org/

my app is not a node app, it's a web app, I am trying to use tdd approach using mocha and chai.

I am confused, on how does mocha understand, that this x test case file is for x source file?

e.g. source file is userArea.js

test file will be in /test folder --> userArea.spec.js (this will have test cases)

When I run test cases through mocha, how does it identify, for what source files, I am running tests?

1

There are 1 answers

1
Louis On BEST ANSWER

Mocha knows what test files it is loading (your *.spec.js files) but it does not specifically know or track what files the tests are testing. When you get a stack trace upon failure, that's not Mocha computing the trace but the JavaScript virtual machine. When you run Mocha in a browser with the HTML interface, you can click to see source code, but that's the source of the test, not the source of the code under test.