Mocha Testing Skeleton
This repo demonstrates how to run mocha + expect.js unit tests in the browser
(or headlessly), with tests written in BDD (Behavior Driven Development) style.
Dependencies:
- mocha - a JavaScript test framework
for running tests on Node.js and the browser
- expect.js - a small BDD-style
assertion library
- mocha-phantomjs - a
PhantomJS test runner for running browser tests headlessly
Included files:
main.js
- the code under testtest/index.html
- an HTML page that sets up the test infrastructure and enables you to run the tests.test/tests.js
- the mocha test suite. The functions "describe()" and "it()" and "afterEach()" are part of mocha; the "expect()" functions are assertion functions that come from expect.js.
Based upon this repo. Altered to meet my needs.
Installing
- Install Node.js and npm from NodeJS.org.
- Use git to clone this repo on your local machine:
$ git clone https://github.com/mjhea0/mocha-testing-skeleton.git
- Enter the repo directory and type
make install
. This installs the dependencies listed above.
Running the tests manually from a browser
- Open the
test/index.html
file in a browser. This displays a test page that shows two tests passing. - Simply refresh the page to run the test suite again.
Running the tests headlessly using PhantomJS
- Run
make test
and observe the results on the command line.