如果您尝试使用浏览器的后退按钮,则我尝试测试一段弹出警报的代码。
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'