Question

I’m writing tests for an Ember.js application with Mocha. I use the ember-mocha-adapter from Teddy Zeenny.

As soon as a promise is involved, the tests fail randomly. I usually get this error:

Error: Assertion Failed: You cannot defer readiness since the `ready()` hook has already been called.

Here is a JS Bin testcase. It contains 10 times the same test and usually fails (tested with Firefox and Chromium).

The same tests run fine with QUnit (maybe by chance :)) (JS Bin testcase). How can I make this work with Mocha? I tried wrapping the promise in an Ember.run() call, but it doesn’t solve the problem.

There is another question about the same problem, but the corrected JS Bin proposed by Teddy Zeenny also fails for me.

Was it helpful?

Solution

There are 3 problems with the code:

  1. It should not call mocha.setup(), as is now explained in the README.
  2. The function calls to setup Ember.js for testing should happen outside any Mocha callback, not in before().
  3. mocha.run() should be called like this:

    Ember.$(function() {
      mocha.run();
    });
    

Here is the fixed JS Bin testcase.

Teddy Zeenny found the solution to this problem in teddyzeenny/ember-mocha-adapter#18.

OTHER TIPS

Really the only reason the qunit is working and mocha isn't is because you're running reset before each test vs after each test.

http://emberjs.jsbin.com/nusewoqi/4/edit

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top