Tim Scott
Tim Scott

Reputation: 15205

QUnit test hangs

I'm new to qunit and JS testing. The code under test does an animation (slideDown) that must completed before I assert. Seems simple, but I can't seem to get it working.

asyncTest('my test', function() {
  setTimeout(function() {
    // assert something here
    start();
  }, 1000);
});

The callback is never called, and the test hangs.

I have tried various other ways too. For example:

test('my test', function() {
  expect(1);
  stop(1000);
  // assert something here
  start();
});

I can see that both start and stop are called, and the test call finishes, but it still hangs.

In case it matters, here's my setup:

setup: function() {
  this.server = sinon.fakeServer.create();
  this.server.respondWith([200, { 'Content-Type': 'text/html' }, new_items()]);
  // invoke the actual system under test
  this.server.respond();
}

Upvotes: 1

Views: 790

Answers (1)

keithjgrant
keithjgrant

Reputation: 12769

It sounds like the Sinon fake timer is on (http://sinonjs.org/docs/#clock). Call this.clock.tick(1001) after setting the timeout.

Upvotes: 1

Related Questions