小编Wes*_*put的帖子

Jest mockRejectedValue 在节点中抛出未处理的承诺拒绝

我试图开玩笑地编写一个测试,但当我尝试使用时不断收到 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, …

javascript typescript jestjs

7
推荐指数
1
解决办法
9148
查看次数

xcode ios 6摇动动作从前一个视图调用IBaction

我对应用程序开发有点新意.在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震动事件中.

我怎么能阻止这个?

iphone xcode motion-detection ios4 ios6

6
推荐指数
1
解决办法
1031
查看次数

标签 统计

ios4 ×1

ios6 ×1

iphone ×1

javascript ×1

jestjs ×1

motion-detection ×1

typescript ×1

xcode ×1