Created
June 10, 2014 21:54
-
-
Save praxxis/88d156af12b26a6d9225 to your computer and use it in GitHub Desktop.
Sinon useFakeTimers and Ember
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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