Skip to content

Instantly share code, notes, and snippets.

@anoras
Created May 27, 2013 09:42
Show Gist options
  • Save anoras/5656157 to your computer and use it in GitHub Desktop.
Save anoras/5656157 to your computer and use it in GitHub Desktop.
it('should trigger an event when things are retrieved', function() {
var server = Sinon.fakeServer.create();
server.respondWith(/\/thing\/(\d+)/, function (xhr, id) {
xhr.respond(200, { "Content-Type": "application/json" }, JSON.stringify(new Thing({ id: id, text: 'Hello' })));
});
var ventInvoked = false;
vent.on('thingReceived', function(thing) {
expect(thing.get('id')).toEqual(123);
ventInvoked = true;
});
vent.trigger('thingRequested', 123);
server.respond();
expect(ventInvoked).toBeTruthy();
server.restore();
});
this.vent.on('thingRequested', function(id) {
var thing = new Thing({ id: id });
thing.fetch({
success: function(thing, response, options) {
self.vent.trigger('thingReceived', thing);
},
error: function(thing, response, options) {
console.error('Unable to get thing');
}
});
});
define([
'lodash',
'backbone'
],
function (_, Backbone) {
return Backbone.Model.extend({
url: function() {
return '/thing/' + this.get('id');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment