3

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();
  });
});
4

1 に答える 1

2

これは、テスト モードで Ember ランループが無効になっていることに関係している可能性があります。チェックアウトしましたic-ajaxか?https://github.com/instructure/ic-ajaxこれは、テストでも、Ember が好む形式で promise スタイルの jQuery ajax リクエストを提供します。テストでの Ember ランループの問題を解決するために導入しましたが、これまでのところ素晴らしい結果が得られています。

teacher.then(..または、でラップすることもできますEmber.run

于 2014-03-12T17:21:07.813 に答える