Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Tools
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

[SF] Standup 7/21/12

Jeff Hui
Tuesday, August 21, 2012

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);

});
});

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Add New Comment Cancel reply

Your email address will not be published.

Jeff Hui

Jeff Hui
San Francisco

Recent Posts

  • Red Bull Book Club Block Party (with fireworks)
  • Valentine’s “pair exchange”
  • [SF] Fireworks provided by Colin!!!
Subscribe to Jeff's Feed

Author Topics

agile (6)
rails (1)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Tools
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >