relevance / blue-ridge

Framework for JavaScript Testing (currently a Rails Plugin)
http://groups.google.com/group/blueridgejs
MIT License
480 stars 40 forks source link

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

Open mudphone opened 15 years ago

mudphone commented 15 years ago

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 commented 15 years ago

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 commented 15 years ago

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

mudphone commented 15 years ago

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 commented 15 years ago

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 commented 15 years ago

@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 commented 15 years ago

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?