我试图开玩笑地编写一个测试,但当我尝试使用时不断收到 UnhandledPromiseRejectionWarningmockRejectedValue
代码如下所示:
it('Should set error message when call fails', async () => {
const context = mockActionsContext();
const user = {
username: 'alice',
password: 'password'
};
const getError = new Error('network error');
(AuthService.login as jest.Mock) = jest.fn().mockRejectedValue(getError);
await actions[ActionTypes.USER_LOGIN](context, user);
// Check is the commits are called
expect((context.commit as any).mock.calls).toEqual([
[MutationTypes.USER_LOGIN],
[MutationTypes.USER_LOGIN_ERROR, 'Oops, something went wrong. Try again later!']
]);
// Login service is called with user login
expect(AuthService.login as jest.Mock).toHaveBeenCalledWith(user);
});
Run Code Online (Sandbox Code Playgroud)
返回AuthService.login一个 axios.post ,我尝试用模拟覆盖它。
actions[ActionTypes.USER_LOGIN](context, …
我对应用程序开发有点新意.在viewController(VPviewController)中,我有以下代码:
- (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{
if (motion == UIEventSubtypeMotionShake){
[self startGame:nil];
}
}
Run Code Online (Sandbox Code Playgroud)
在另一个viewController(VPgameViewController)中,我有一个不同的MotionShake事件:
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
if(event.subtype == UIEventSubtypeMotionShake){
if(count < 3 ){
[self changeText:nil];
AudioServicesPlaySystemSound(1016);
count++;
}else{
count = 0;
AudioServicesPlaySystemSound(1024);
UIStoryboard *storyboard = self.storyboard;
VPpoepViewController *shit = [storyboard instantiateViewControllerWithIdentifier:@"PoepViewController"];
shit.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:shit animated:YES completion:nil];
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我在VPgameView中并摇晃Iphone时,它还调用了startGame函数,该函数位于不同的viewController震动事件中.
我怎么能阻止这个?