Close
Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

PIVOTAL LABS
[SF] Standup 7/21/12

Interestings

  • Always call jasmine.Clock.useMock() after anything that uses setTimeout or setInterval (e.g. _.throttle)

This is smallest example that reproduces the problem we saw in our codebase:

describe(”underscore”, function() {
var foo, throttledFoo;

beforeEach(function() {
jasmine.Clock.useMock(); // bad!

var Mod = Backbone.RelationalModel.extend({});
var Col = Backbone.Collection.extend({model: Mod});
new Col([{selected: false, trashed: false}]);

foo = jasmine.createSpy();
throttledFoo = _.throttle(foo, 500);

// jasmine.Clock.useMock(); // good!
});

it(”should 1″, function() {
throttledFoo();
});

it(”should 2″, function() {
throttledFoo();
});

it(”should 3″, function() {
});

it(”should 4″, function() {
});

it(”should consistently pass but doesn’t”, function() {
expect(foo.calls.length).toEqual(0);
throttledFoo();

expect(foo.calls.length).toEqual(1);

throttledFoo();

expect(foo.calls.length).toEqual(1);

jasmine.Clock.tick(501);

expect(foo.calls.length).toEqual(2);

});
});

Comments
Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *