我试图模拟我的应用程序中使用的警报
这是我的工厂代码
app.factory('Handler', ['config', '$location',function (config, $location){
return {
log: function (message, data) {
if (config.DEBUG) {
alert('Alert Message (' + message + "):\n" + JSON.stringify(data));
}
}
}
}]);
Run Code Online (Sandbox Code Playgroud)
我尝试将此警报的模拟测试编写为
describe("checking Handler service " , function(){
var Handler, mock ;
beforeEach(module("MyApp"));
beforeEach(function(){
mock = {alert: jasmine.createSpy()};
inject(function(_Handler_){
Handler = _Handler_;
});
});
it("should check for alert",function(){
spyOn(Handler, "log");
Handler.log('A','B');
expect(mock.alert).toHaveBeenCalledWith('Alert Message (A):\n "B" ');
});
Run Code Online (Sandbox Code Playgroud)
});
但是当我尝试运行茉莉花测试时,我收到此错误
Expected spy unknown to have been called with [ 'Alert Message (A): …Run Code Online (Sandbox Code Playgroud)