Adds chai assertions for the js-signals library.
Adds the following assertions to chai:
- dispatched()
- dispatchedWith()
How to use
Installation
Important: The expectations in this package are dependent on signals from js-signals.
npm install chai-signals
Create
First define which signals you're interested in.
var signal = ;var signalSpy = chaisignals;var signalSpies = chaisignals;
Filtering signals
You can pass a boolean function to specify which dispatches to register.
var signal = ;var signalSpy = chaisignals;signal; // ignoredsignal; // registered
Expectations
After defining the spy you can set expectations in your tests.
tohavebeen; // the spy's signal has been dispatched at least oncetohavebeen; // the spy's signal has been dispatched n timestohavebeen; // the signal has been dispatched at least oncetohavebeen; // the signal has been dispatched n timestonothavebeen; // the spy's signal has not been dispatched at alltonothavebeen; // the spy's signal has not been dispatched n timestonothavebeen; // the signal has not been dispatched at alltonothavebeen; // the signal has not been dispatched at all tohavebeen; // the spy's signal has been dispatched using ntohavebeen; // the spy's signal has been dispatched using (m, n)tohavebeen; // the spy's signal has been dispatched with using objecttohavebeen; // the signal has been dispatched using ntohavebeen; // the signal has been dispatched using (m, n)tohavebeen; // the signal has been dispatched with using objecttonothavebeen; // the spy's signal has not been dispatched using ntonothavebeen; // the spy's signal has not been dispatched using (m, n)tonothavebeen; // the spy's signal has not been dispatched with using objecttonothavebeen; // the signal has not been dispatched using ntonothavebeen; // the signal has not been dispatched using (m, n)tonothavebeen; // the signal has not been dispatched with using object
AMD
It's possible to use chai-signals
as an AMD (Asynchronous Module Definition) module.
chai-signals
depends on JS-Signals, so first define signals
path:
require;
Then use it in Chai
tests like this:
;
If you are using karma to run tests make sure to include chai.use(chaiSignals);
in each of your test files.
Examples
See tests for usage:
Development
Install node.js, bower.
npm installbower installnpm test
License
This code is distributed under the MIT license.
Credit
This plugin is based off of Adam Nowotny's jasmine-signals.