【发布时间】:2017-04-12 14:38:55
【问题描述】:
为什么我写这样的代码不能测试注销的分支? 这是 Jest 官方示例。链接在这里 https://github.com/facebook/jest/blob/master/examples/jquery 原始测试代码只是测试登录分支,所以我想测试整个分支。但我无法完成它:(
fetchCurrentUser.mockImplementationOnce(cb => {
cb({
fullName: 'Johnny Cash',
loggedIn: true,
});
}).mockImplementationOnce(cb => {
cb({
fullName: 'Johnny Cash',
loggedIn: false,
});
});
$('#button').click();
expect(fetchCurrentUser).toBeCalled();
expect($('#username').text()).toEqual('Johnny Cash - Logged In');
$('#button').click();
expect(fetchCurrentUser).toBeCalled();
expect($('#username').text()).toEqual('Johnny Cash - Logged Out');
【问题讨论】:
标签: jestjs