Question

I am writing an integration test for my Ember.js application in QUnit. Before a test, I want to seed some test data by issuing HTTP requests to a dedicated testing API. I use jQuery.post to issue POST requests and I use Ember.RSVP.Promise.cast to turn the jQuery promise into an RSVP promise. However, it never seems to resolve. In the code below, it just hangs. The string "STARTING" is printed but neither "DONE" nor "FAIL" is printed.

I also tried creating a new RSVP Promise as described in the "Advanced usage" section of http://emberjs.com/api/classes/Ember.RSVP.Promise.html, to no avail (it also hanged). If I don't wrap the jQuery promise into an RSVP Promise, it does reach either the "DONE" or "FAIL".

Why doesn't the RSVP Promise resolve?

function create_teacher() {
  var url = "<%= testing_teacher_path %>";

  return Ember.RSVP.Promise.cast(
    Ember.$.post(
      url,
      {
        user: {
          first_name: "John",
          last_name: "Doe"
          school: "EE3",
          email: "john@doe.com",
          password: "password"
        }
      }
    )
  );
}

module("Teacher Dashboard", {
  setup: function() {
    console.log("STARTING");
    Ember.run(HstryEd, HstryEd.advanceReadiness);
  },
  teardown: function() {
    console.log("TEARING DOWN");
    HstryEd.reset();
  }
});

asyncTest("Login", function() {
  expect(1);

  var teacher = create_teacher();
  teacher.then(function() {
    console.log("DONE");
    ok(true, "done");
    start();
  },
  function() {
    console.log("FAIL");
    ok(false, "fail");
    start();
  });
});
Was it helpful?

Solution

It could have to do with the Ember runloop being disabled in test mode. Have you checked out ic-ajax? https://github.com/instructure/ic-ajax It gives you promise-style jQuery ajax requests in a form that Ember likes, even in testing. I brought it in to solve my Ember runloop issues in testing, and have had great results so far.

Alternatively, you could try wrapping your teacher.then(.. in an Ember.run.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top