feather-test
Extremely lightweight JavaScript test coverage
Refactor safely -- without configuring a burdensome test suite
Need to test JavaScript for browsers? Use feather-test-browser
Install
$ npm install feather-test --save-dev
Write Some Tests
myProject/test/specs/one.spec.js
;
myProject/test/specs/two.spec.js
// example of an asynchronous test;
myProject/package.json
"scripts": "test": "node ./test/run"
myProject/
|--test/
| |--specs/
| | |--one.spec.js
| | |--two.spec.js
| |--run.js
|--src/
| |--etc.
|--package.json
Run Your Tests
myProject/test/run.js
var FeatherTest = ; // create a new FeatherTest with your spec filesvar myTests = helpers: './helpers' specs: './specs'; // run all queued tests by calling `run`// (optional callback will be executed after all tests finish)myTests;
$ cd myProject
$ npm test
// All 4 tests passed!
Matchers
Any of the below can also be negated using not.toBe, etc.
- toBe
- toBeGreaterThan
- toBeLessThan
- toContain
- toEqual
- toHaveBeenCalled
- toHaveBeenCalledWith
Spec Methods
The following methods are globally available within spec files
describe
The basic building block of specs. A description explains what features will be tested within. (can be nested)
;
xdescribe
Skips this block and all assertions within. Also skips nested describes.
;
it, xit
Alias for describe
(above). Added to make migrations easier
any
Use with matchers to indicate a match with and object that shares the same constructor
;
clock
Manage timing events. Installing will add a global override for setTimeout
and setInterval
. To advance the clock use clock.tick(amount)
.
;
spy
Stub or mock any function or method.
spy.on()
watches and counts each invocation.
;
spy()
creates a new spy.
;
Pass a closured reference into async blocks to avoid having your spied functions reset.
var obj = { console; }; ;
Configuration Options
new FeatherTest(options)
helpers
Files (or a directory of files) to load before your specs
specs
The files (or a directory of files) that contain your specs
beforeEach
A function to execute before each describe
afterEach
A function to execute after each describe
customMatchers
An array of matchers to add to the expect() return object
customMatchers: name: 'toMatchCustom' message: 'to match custom things' { return expected === actual * 3; }
stopAfterFirstFailure
If set to true
specs will halt execution after the first spec fails
timeout
How long (in ms) to wait for an async describe to call done()
Build
We use Travis CI. Here's a link to the build: https://travis-ci.org/feather-test/feather-test