Backbone assertions for the Chai assertion library
chai-backbone is an extension to the chai assertion library that provides a set of backbone specific assertions.
Use the assertions with chai's
modelshouldtrigger"change"with: modelwhen ->modelset attribute: "value"
this can also be chained further:
modelshouldtrigger"change"andtrigger"change:attribute"when -> modelset attribute: "value"modelshouldtrigger"change"andnottrigger"reset"when -> modelset attribute: "value"
Tests if a route is delegated to the correct router and if the arguments are extracted in the expected manner.
"page/3"shouldrouteto myRouter"openPage"arguments: "3""pages/3"shouldnotrouteto myRouter"openPage""page/3"shouldrouteto myRouter"openPage"considering: conflictingRouter
This assertion is ideal for testing view callbacks it will rebind view events to test DOM events
viewshouldcall'startAuthentication'when ->view$'a.login'trigger 'click'
npm install chai-backbone to get up and running. Then:
var chai = require"chai";var chaiBackbone = require"chai-backbone";chaiusechaiBackbone;
You can of course put this code in a common test fixture file; for an example using Mocha
Chai Backbone supports being used as an AMD module, registering itself anonymously (just like Chai). So,
assuming you have configured your loader to map the Chai and Chai
Backbone files to the respective module IDs
"chai-backbone", you can use them as follows:
definevar chai = require"chai";var chaiBackbone = require"chai-backbone";chaiusechaiBackbone;;
If you include Chai Backbone directly with a
<script> tag, after the one for Chai itself,
then it will automatically plug in to Chai and be ready for use:
Copyright (c) 2012 Matthijs Groen
MIT License (see the LICENSE file)