私は Jasmine ( http://pivotal.github.com/jasmine/ ) に精通しており、やや不可解なものを見つけました:
it("should be able to send a Ghost Request", function() {
var api = fm.api_wrapper;
api.sendGhostRequest(function(response) {
console.dir('server says: ', response);
});
expect(true).toEqual(false);
});
期待どおりに失敗します。
ただし、expect 呼び出しをコールバック内に移動します。
it("should be able to send a Ghost Request", function() {
var api = fm.api_wrapper;
api.sendGhostRequest(function(response) {
console.dir('server says: ', response);
expect(true).toEqual(false);
});
});
何とか合格 :O
いくつかのデバッグの後: api.sendGhostRequest() は非同期 ajax リクエストを実行し、jasmine はリクエストが完了する前に急いで通り過ぎます。
したがって、質問:
テスト結果を確認する前に、jasmine に ajax の実行を待機させるにはどうすればよいですか?