Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with testing #38

Closed
tonegarot opened this issue Nov 26, 2013 · 3 comments
Closed

Issue with testing #38

tonegarot opened this issue Nov 26, 2013 · 3 comments

Comments

@tonegarot
Copy link

We've been having problems with unit tests. The test was fairly straight forward:

test("Login, render dashboard", function() {
  expect(1);
  visit("/user/login");
  fillIn("#identification","test");
  fillIn("#password","test");
  click("#btnLogin");
  andThen( function() {
    equal(find(".island").length, 4, "Multiple islands should be rendered");
  });
});

And the result in the console was:

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 an Ember.run

In the debugger, we stepped through jQuery where it executes callbacks for AJAX responses. Eventually we found it. We needed to wrap your functionality with Ember.run() in your login function. This is around like 439 of ember-simple-auth.js in version 0.0.9.

Ember.run(function() {
  _this.get('session').setup(response);
  _this.send('loginSucceeded');
});

This has fixed the issue! Thought you should know.

Regards.

@marcoow
Copy link
Member

marcoow commented Nov 26, 2013

An explicit Ember.run should actually never be necessary in production code as the autoron-run-loop is always active (as the error message you're seeing indicates). If you change your test to

test("Login, render dashboard", function() {
  expect(1);
  visit("/user/login");
  fillIn("#identification","test");
  fillIn("#password","test");
  Ember.run(function() {
    click("#btnLogin");
  })
  andThen( function() {
    equal(find(".island").length, 4, "Multiple islands should be rendered");
  });
});

that probably fixes the problem as well and is cleaner.

@tonegarot
Copy link
Author

I agree that this "should" work. This was the first thing we tired. The click helper is actually wrapped in an Ember.run().

We thought that perhaps you might want to use a combination of if ( Ember.testing ) and our proposed Ember.run() in combination in your login code. It works great in production code, just not in our testing.

@marcoow
Copy link
Member

marcoow commented Nov 26, 2013

I think adding an Ember.run to the code when Ember is in testing mode would really only fix the symptom and not the actual problem. The error message you're seeing actually describes the problem quite well - in testing mode there's no autorun run loop so here and there, stuff needs to be wrapped in Ember.run. This really belongs in the test (or maybe in ember-testing) but not in the source of the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants