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

How does mocha do asynchronous tests in browser? #217

Closed
deepinsource opened this issue Jan 16, 2012 · 5 comments
Closed

How does mocha do asynchronous tests in browser? #217

deepinsource opened this issue Jan 16, 2012 · 5 comments

Comments

@deepinsource
Copy link

var a = 10;
setTimeout(function(){ a = 20; }, 0)  // don't change here

// What does mocha do here ???
// Does mocha have 'stop' method like qunit ?

assert(a === 20);
@tj
Copy link
Contributor

tj commented Jan 16, 2012

it('should be async', function(done){
  doSomethingAsync(function(){
     assertSomething();
     done();
  });
});

@tj tj closed this as completed Jan 16, 2012
@deepinsource
Copy link
Author

// source code                   I don't want to chang it
function setState(el) {
  setTimeout(function(){
    el.addClass('active')
  }, 0)
}
--------------------------------------------------------------------------
// test code
it('', function(){
  var $el = $('document.body')
  setState($el)
  // how to test this without changing the source?
  // has something similar to qunit's stop method?
  assert($el.hasClass('active'))
})

@tj
Copy link
Contributor

tj commented Jan 16, 2012

just setTimeout with 0 again and call done() in it, it'll fire after the other one

@tj
Copy link
Contributor

tj commented Jan 16, 2012

not sure what stop() does in qunit, js has no sleep(), so i dont know what it would do

@deepinsource
Copy link
Author

Thanks

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

No branches or pull requests

2 participants