我是JQuery的新手,必须使用Jasmine测试此功能:
showUserDeleted: function (event) {
$('#loginError').html((new ErrorView({code: "login"})).render().$el);
}
我将这个功能分成两部分:
showFailedLogin: function (event) {
var value = (new ErrorView({code: "login"})).render().$el;
showFailedLoginHelper(event, value);
},
showFailedLoginHelper: function (event, value){
$('#loginError').html(value);
},
现在我想测试辅助函数。
//...
var view;
var $;
beforeAll(function(done){
require(['../../../public/js/app/views/LoginView', 'jquery'],
function(LoginView, Jquery) {
view = new LoginView();
$ = view.getJQuery();
done();
}
);
});
describe("showFailedLogin", function(){
it ("should add something to loginError", function(){
var input = "asdf";
view.showFailedLoginHelper(undefined, input);
expect( $('#loginError').html()).toBe(input);
});
});
//...
当我运行时,它说:
Expected undefined to be 'asdf'.
我做错了什么?