我正在制作一个 android 应用程序,要求用户通过微调器选择一个国家。
当用户第一次打开应用程序时,用户从列表中选择一个国家。
然后当应用程序第二次打开时,我希望选择同一个国家。我不希望用户每次打开应用程序时都选择国家。怎么做?
我正在处理一个 React 项目,并且正在使用 jest 为我的代码编写测试。
这是我要测试的代码。
const handleSubmit = (handleSuccess, handleErrors) => {
signupAPI(user)
.then(handleSuccess)
.catch(handleErrors);
};
Run Code Online (Sandbox Code Playgroud)
这是测试代码:
test('should call handleSuccess', () => {
signupAPI.mockImplementation((user) => Promise.resolve(user));
const handleSuccess = jest.fn();
const handleErrors = jest.fn();
handleSubmit(handleSuccess, handleErrors);
expect(signupAPI).toHaveBeenCalled(); // test passes
expect(handleSuccess).toHaveBeenCalled(); // test fails
});
Run Code Online (Sandbox Code Playgroud)
当我运行测试时,它永远不会在承诺之后移动到“then”部分。如何测试 then 部分中的函数是否被实际调用?