Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stubbing global method (setTimeout) seems to stop test execution. #12

Open
mudphone opened this issue Jun 16, 2009 · 6 comments
Open

Stubbing global method (setTimeout) seems to stop test execution. #12

mudphone opened this issue Jun 16, 2009 · 6 comments

Comments

@mudphone
Copy link

If I place the following override in a before call:
before(function(){
setTimeout = function () {print('setTimeout stub');};
});

Then, the following tests do not execute as I would expect. The first following test runs, but then all the rest of the tests do not run.

  it("should...", function(){
    print('start test1');
  });

  it("should...", function(){
    print('start test2');
  });

  it("should...", function(){
    print('start test3');
  });

My test output looks like this:
.......start test1
.setTimeout stub

As you can see, test2 and test3 are never executed. Am I don't something wrong here?

Thanks!

@mudphone
Copy link
Author

Is it possibly that 'setTimeout' is a bad thing to be stubbing out (and possibly used by the Blue-Ridge framework)? If so, 'doh' (on me).

@karnowski
Copy link

We're definitely not using setTimeout in Blue Ridge, but maybe Screw.Unit is? We'll look into it.

@mudphone
Copy link
Author

Thanks! The night after I posted my comment, I noticed in John Resig's JS "Ninja" book, that he gives a simple example of a JS testing framework that uses setTimeout to queue tests. So, perhaps it is indeed in Screw.Unit.

@drnic
Copy link

drnic commented Jul 27, 2009

Does anyone have samples of testing behaviour that does take some time to complete? how do we "wait X seconds" before asserting that some behaviour has been performed?

@gf3
Copy link

gf3 commented Aug 7, 2009

@drnic - Perhaps there is a better way of accomplishing this test, as JS is single-threaded. Maybe passing callback or firing an event would be better?

@wireframe
Copy link

i'm stuck with the same issue. i'm trying to test code that uses setTimeout and the test completes before the code is executed. does screwunit support some kind of asyn callback for testing?

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

No branches or pull requests

5 participants