5

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

Balwant Singh
  • 287
  • 5
  • 14

1 Answers1

14

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');
    });
}
Toran Billups
  • 27,111
  • 40
  • 155
  • 268
  • Works. It's unfortunate though that I now have to wrap hundreds of .set() just to make the components tests pass ... :expressionless: – Jan Werkhoven Apr 13 '16 at 02:15
  • @JanWerkhoven truthfully you isolate this in your single ajax function/helper in the app. Something like you see in this ajax/promise helper I use in my ember apps https://github.com/toranb/ember-promise/blob/master/addon/mixins/promise.js#L12 – Toran Billups Apr 13 '16 at 16:55
  • what are you using to fire off ajax requests right now? if you don't have a "single function/ object" maybe now is a good time to refactor :) – Toran Billups Apr 13 '16 at 16:59
  • @JanWerkhoven you could wrap the operation in that particular test in `Ember.run()`, not in your code. For example if you're calling a method on a service that causes this error, just wrap that method call in your test in `Ember.run()`. – emil.c Nov 18 '16 at 11:06