无法开玩笑地掩盖以下陈述。
initListener = (logout, refreshToken) => {
document.body.addEventListener("click", () => this.reset(logout, refreshToken));
document.body.addEventListener("onkeydown", () => this.reset(logout, refreshToken));
document.body.addEventListener("onkeyup", () => this.reset(logout, refreshToken));
document.body.addEventListener("onkeypress", () => this.reset(logout, refreshToken));
};
和
logout = (logout, refreshToken) => {
logout();
redirect(appConstants.LOGIN, []);
document.body.removeEventListener("click", () => this.reset(logout, refreshToken));
document.body.removeEventListener("keydown", () => this.reset(logout, refreshToken));
document.body.removeEventListener("keyup", () => this.reset(logout, refreshToken));
document.body.removeEventListener("keypress", () => this.reset(logout, refreshToken));
storageClearAll();
};
答案 0 :(得分:0)
我同意@lonut,这不是做事的一种反应方式。
尽管如此,是否需要测试……
测试前:
{
faultcode: 500,
faultstring: 'Invalid XML',
detail: 'Error: Unquoted attribute value\nLine: 75\nColumn: 14\nChar: c',
statusCode: 500
}
在测试中,可以检查是否添加了侦听器并模仿这样的事件
document.body.addEventListener = jest.fn((event, cb) => {
map[event] = cb;
});