Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember Error while testing: You will need to wrap any code with asynchronous side-effects in a run

We already have a app working just working to add test cases to it for the purpose of CI.

We have a small code that tries the login process and checking what happens after the possible login states like success, failure, invalid account account locked etc.

so the I tried the follwing code.

visit('/login')
    .fillIn('#identification', "testuser")
    .fillIn('#password', "testpass")
    .click('input[type="submit"]')
    andThen(function(){
        ok(!exists('button:contains(sign in)'), '3. Login button is not displayed when authenticated');
        ok(exists('.dropDownMenuOptions li:contains(Logout)'), '4. Logout button is displayed when authenticated');
    });

and it gives the following error in console.

ember.debug.js:5162 Uncaught Error: Assertion Failed: You have turned on testing mode, which disabled the run-loop's autorun. You will need to wrap any code with asynchronous side-effects in a run

This error occurs after the click is performed. as the click makes the AJAX call to server and on its response the route transition is made.

For the case of successful login, I want to check if my route changed from /login to / which I am not able to do because of this error.

Please suggest.

Thanks

like image 707
Balwant Singh Avatar asked Jul 17 '15 02:07

Balwant Singh


1 Answers

In the controller/component that handles your form submit you must be doing a set (example)

save: function() {
    this.get('model').set('name', 'foo');
}

If this work is done in the run loop (async) after some ajax event be sure to wrap it w/ ember run like so

save: function() {
    Ember.run(function() {
        this.get('model').set('name', 'foo');
    });
}
like image 71
Toran Billups Avatar answered Sep 28 '22 08:09

Toran Billups