Skip to content

Instantly share code, notes, and snippets.

@praxxis
Created June 10, 2014 21:54
Show Gist options
  • Save praxxis/88d156af12b26a6d9225 to your computer and use it in GitHub Desktop.
Save praxxis/88d156af12b26a6d9225 to your computer and use it in GitHub Desktop.
Sinon useFakeTimers and Ember
test('creates a local creation time property when saving', function () {
expect(1);
var now = new Date().getTime(),
clock = sinon.useFakeTimers(now),
model = App.Model.create(),
promise = Em.RSVP.resolve(),
superStub = sinon.stub(model, '_super').returns(promise);
model.save().then(function () {
equal(model.get('locallyCreated'), now, 'the models locallyCreated property is the current timestamp');
});
// RSVP uses setTimeout to mimic async promises, but the sinon fake clock stubs setTimeout. Thus, tick forward a
// millisecond to force the async promise to resolve.
clock.tick(1);
superStub.restore();
clock.restore();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment