Skip to content
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.

setTimeout/setInterval do not catch errors #22

Open
polotek opened this issue Jul 19, 2011 · 0 comments
Open

setTimeout/setInterval do not catch errors #22

polotek opened this issue Jul 19, 2011 · 0 comments

Comments

@polotek
Copy link
Contributor

polotek commented Jul 19, 2011

Foounit has waitFor and waitForTimeout keywords for doing asynchronous testing. But these aren't good for the simple use case of running a simple function once. What I'm doing is mocking ajax calls. Here's a simplified example.

var fakeAjax = {
   send: function(req) {
      var fakexhr;
      foounit.setTimeout(function() {
          req.success && req.success('data', 'success', fakeXHR);
      }, 10);
   }
}

The problem comes in when I want to put expect statements inside the success function. Since setTimeout isn't test aware, the errors propagate to the top of the runtime but do not make the test fail. Here's the simplest test for this issue.

foounit.add(function (kw){ with (kw){
  describe('waitFor', function() {
    it('fails if timeout throws', function() {
      var end = false;
      foounit.setTimeout(function() {
        end = true;
        expect(false).to(beTrue);
      }, 100);

      waitFor(function() {
        expect(end).to(beTrue);
      }, 1000);
    });
  });
}});

This test passes, but the expect in setTimeout should be caught and cause it to fail.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant