I use Karma, Jasmine, Jasmine. Asink, Sinon and Tea.
The good news is ... this test is working correctly. Dependence mocks, spies receive a call, and intentional violation of the test object leads to unsuccessful trials.
define(['chai', 'squire'], function (chai, Squire) { var should = chai.should(), async = new AsyncSpec(this), subject, injector = new Squire(); describe('EventsView', function () { describe('when an event is clicked', function () { var mockModel, stub; async.beforeEach(function (done) { setFixtures('<div id="screen"></div>'); mockModel = { toJSON: function () { return { dimensions: "hu1 vu2", events: [{ date: "8/29/2013", id: "8923", title: "Fancy Show", venue: "Lovely venue", }, { date: "8/29/2013", id: "9034", title: "Exciting Game", venue: "Lovely stadium" }], id: 3566, kind: "events", title: "Top events this week" }; }, fetch: function () {} }; stub = sinon.stub(); injector.mock('tiles/events-tile/events-detail-model', Squire.Helpers.constructs({ fetch: stub })); injector.require(["tiles/events-tile/events-view"], function (ev) { subject = new ev(mockModel); done(); }); }); async.afterEach(function (done) { injector.clean(); injector.remove(); done(); }); async.it('should attempt to fetch the event details', function (done) { $('#screen').html(subject.$el); $('.event').first().click(); stub.called.should.be.true; done(); }); }); }); });
The bad news ... the load of other tests that were previously excellent now fails for unknown reasons. For example: Error: Backbone.history has already been started as well as TypeError: 'undefined' is not an object (evaluating 'Backbone.Validation.mixin')
If I comment on the fragment
injector.require(["tiles/events-tile/events-view"], function (ev) { subject = new ev(mockModel); done(); });
Then the rest of the tests work again. I used to have things like this before, and usually it was until the sinon recovered. Calling injector.clean() doesn't seem to provide the magic bullet I was hoping for.
javascript requirejs karma-runner jasmine squirejs
Dakuan
source share