预期警报后调用间谍警报

时间:2019-07-04 07:15:02

标签: javascript jasmine karma-jasmine jasmine2.0

如果您尝试使用浏览器的后退按钮,则我尝试测试一段弹出警报的代码。

var msg = '';
spyOn(window, 'alert').and.callFake((arg) => {
    msg = 'Alert Was Called';
    console.log("My Alert Was Called");
});

history.back();

expect(msg).toEqual('Alert Was Called');
console.log('After Expect Statement');

测试失败,并出现以下错误 Expected '' to equal 'Alert Was Called'.和日志按以下顺序:

LOG: 'After Expect Statement'
LOG: 'My Alert Was Called'

0 个答案:

没有答案