teddyzeenny / ember-mocha-adapter

A mocha adapter for ember-testing.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

using assertion library “expect” within promise does not work

dshrestha opened this issue · comments

Hi there, I want to begin with thanks for creating this adapter without which testing ember app with mocha would have been impossible.
I have been facing an issue which I think is associated with the adapter but I may be wrong. When using "expect" asserts within a promise I always get a js error. I had posted this issue in stackoverflow here: http://stackoverflow.com/questions/20005458/using-assertion-library-expect-within-promise-does-not-work?noredirect=1#comment29873715_20005458

Thanks,
Dee

That is strange. Can you copy paste the exact test that is failing? There may be a minor issue that you omitted when coming up with the example.

Hi there, I am sorry for the late response. I have been trying to create a JS bin for quite some time now but I couldn't get things working there because of lack of cdnjs lib, I tried to include the raw script itself but that didn't work either. So I am attaching the whole script in jsbin here : http://jsbin.com/OlUVoBEJ/1/, please replace the "lib/scripts/*.js" with your copy of the scripts and try the script locally.

Remove mocha.setup('bdd'); and it should probably work. Will reopen if this doesn't fix it.

Hi there, an easy way to re-create this issue is to do something like this

it("dummy test", function () {
    Ember.run.later(this, function(){
        expect(true).to.be(false);
    }, 500);
});

This causes same issue, even when we remove mocha.setup('bdd'). The test passes but we get an error in the console "Error: expected true to equal false". Is there a way we can handle such case?

that is because you need to call wait() at the end (all async helpers like visit call wait).

it("dummy test", function () {
    Ember.run.later(this, function(){
        expect(true).to.be(false);
    }, 500);
   wait();
});

Thanks a lot, that did the trick.