3
測試我的骨幹模型的觸發方法時,我得到了一個奇怪的錯誤。下面是我的代碼:茉莉花測試骨幹模型的觸發方法
Category = Backbone.Model.extend({
fetchNotes: function() {
this.trigger("notesFetchedEvent");
}
})
describe("Category", function() {
it("should fetch notes", function() {
var category = new Category;
spyOn(category, "trigger");
category.fetchNotes();
expect(category.trigger).wasCalledWith("notesFetchedEvent");
})
})
我得到的錯誤是「預期間諜觸發已經調用[‘notesFetchedEvent’],但被稱爲與...... jibberish ......」。有誰知道如何解決這一問題?謝謝。
在jasmine1.1.0-rc1下正常工作也許有些東西導致了javascript錯誤?檢查你的控制檯。 – Gazler 2012-01-11 21:32:47
您是否可以使用'expect(category.trigger).toHaveBeenCalledWith(「notesFetchedEvent」)'來嘗試它,因爲'wasCalledWith'已棄用。 – 2012-01-11 21:33:02
toHaveBeenCalledWith不適用於我。上面的代碼只是示例代碼來說明我的觀點。我的完整代碼是在http://pastie.org/private/ttkougq7n7jg4zx3hliq(category模型)和http://pastie.org/private/uh4dxauteb7qvt6pgkp1hq(測試) – 2012-01-11 21:43:06