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.

Include chai-backbone.js in your test file, after chai.js (version 1.0.0-rc1 or later):

<script src="chai-backbone.js"></script>

Use the assertions with chai's expect or should assertions.

model.should.trigger("change", with: [model]).when -> model.set attribute: "value"

this can also be chained further:

model.should.trigger("change").and.trigger("change:attribute").when -> model.set attribute: "value"
model.should.trigger("change").and.not.trigger("reset").when -> model.set attribute: "value"

Tests if a route is delegated to the correct router and if the arguments are extracted in the expected manner.

"page/3" myRouter, "openPage", arguments: ["3"]
"page/3" myRouter, "openPage", considering: [conflictingRouter]

This assertion is ideal for testing view callbacks it will rebind view events to test DOM events'startAuthentication').when ->
  view.$('a.login').trigger 'click'

Copyright (c) 2012 Matthijs Groen

MIT License (see the LICENSE file)