2
votes

I am trying to setup ember.js with QUnit to write integration tests.

Following the directions on http://emberjs.com/guides/testing/integration/ I have:

document.write('<div id="ember-testing-container"><div id="ember-testing"></div></div>');

App.rootElement = '#ember-testing';
App.setupForTesting();
App.injectTestHelpers();

module("Integration Tests", {
  setup: function() {
    App.reset();
  }
});

test("root lists first page of posts", function(){
  visit("/").then(function() {
    equal(find(".post").length, 5, "The first page should have 5 posts");
    // Assuming we know that 5 posts display per page and that there are more than 5 posts
  });
});

However when I run QUnit I get the following 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 an Ember.run 

This assertion error is triggered because I am making a http request in the app initializer to check if there is a current user session. This returns a 401 error if there is no valid user. (If I force the app to always return 200 for this request, this assertion error does not occur and the tests continue as expected).

I believe the app and API is behaving correctly by returning a http error for an invalid user, and I don't want to change to response to a 200 just to get my tests working. What do I need to do to get ember and QUnit to handle a http error and assertion? From what I've read I need to wrap something with Ember.run, but I can't figure out what.

1
Are you still having this problem? Maybe I could help.Marcio Junior
By all means, please help. StackOverflow is still helpful for those of us who also have this problem. So if you know the answer, or have an idea, please write up an answer. I'm having this problem, and your comment was not helpful at all. Still looking...Luc

1 Answers

0
votes

Your unit and integration tests should ideally run in isolation from external resources (like an HTTP API), so mocking HTTP requests is the easiest pattern.

To get truly full-stack smoke testing, you'll want to exercise the app with browser automation tools like PhantomJS.