teddyzeenny / ember-mocha-adapter

A mocha adapter for ember-testing.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Be able to manually calling done()

eoinkelly opened this issue · comments

I am running into trouble with a test where I want to manually control when done() is invoked. Here is an example:

it('should inform the user that they got the answer wrong', function (done) {
  visit('/testing123')
  .then(function () {

    // a helper that makes the app's root DOM node visible. CSS Animations do
    // not run unless they are visible (presumably a performance thing)
    showEmberRoot();

    var listener = function (e) {
      // Yay the animation ran!
      done();
    };

    left.addEventListener('webkitAnimationStart', listener, false);
  })
  .click('.thing')
  .click('.other-thing')
  .then(function () {
    hideEmberRoot();
  });
});

In the example above, the user clicks on stuff that triggers the addition of a class to an element. This class triggers a CSS animation and is removed when the animation finishes. This makes it tricky to test because sometimes the animation has finished and the class has been removed before the test can get to it.

The error I get is that Mocha complains that done() is called twice. This makes sense as I call done in listener() and the adapter calls it too. Just to be clear, I'm not asking/expecting you to fix my test 😄 - there are a few ways I can get around this for this particular instance but in general it would be very convenient to be able to use the done callback in tests - it is one of Mocha's best features I think. Is this something that you would consider addressing in the adapter? I am happy to try and PR something if you feel like it is a feature you would consider.

If you have done as your function's parameter, function (done) the adapter will no longer call done.

The more probable case is that listener function is being called twice.

Yep I was neglecting to calling removeListener after the test. Sorry to take up your time.