0
我有一個Backbone應用程序,我正在研究所有功能都在App
下的命名空間。我有一個叫App.LoginView
的視圖,我想用Jasmine來測試它,但是我正在努力讓它工作。檢查使用Jasmine調用的骨幹視圖方法
這是測試代碼:
describe("Test the views", function() {
'use strict';
beforeEach(function() {
// Create DOM element
$('body').append('<div class="content"></div>');
});
afterEach(function() {
$('div.content').remove();
});
// Test the LoginView object was created
it("tests that the LoginView object exists", function() {
// Check the view definition exists
expect(App.LoginView).toBeDefined();
// Spy on the prototype
spyOn(App, 'LoginView').andCallThrough();
// Create the view
this.LoginView = new App.LoginView();
// Check the view exists
expect(this.LoginView).toBeDefined();
expect(this.LoginView.initialize).toBeDefined();
expect(this.LoginView.template).toBeDefined();
expect(this.LoginView.tagName).toBeDefined();
expect(this.LoginView.render).toBeDefined();
// Remove it
this.LoginView.remove();
});
});
它引發以下錯誤:
TypeError: 'undefined' is not a function (evaluating 'spyOn(App, 'LoginView').andCallThrough()')
我使用grunt-contrib-jasmine
運行測試和jasmine-jquery
增加對jQuery的支持。過去我曾經使用過茉莉花,但是我正努力去看看我在這裏出了什麼問題。