Я пытаюсь проверить методы после выполнения обещания, используя Jest и энзим.Мой компонент / функциональный код:
// Functional Code
let functionAfterAsync = () => {
console.log('functionAfterAsync called');
}
const asyncFunction = () => {
return new Promise(resolve => resolve());
}
const functionWithAsyncCode = () => {
// ... some more code here
console.log('functionWithAsyncCode');
asyncFunction().then((res: any) => {
functionAfterAsync();
})
}
Мой тест:
functionAfterAsync = jest.fn();
// Tests
describe('<Async Test />', () => {
it('Call function after promise', () => {
functionWithAsyncCode();
expect(functionAfterAsync).toBeCalled();
})
});
Но functionAfterAsync
не вызывается, и я получаю ошибку: expect(jest.fn()).toBeCalled() Expected mock function to have been called.
Есть ли способ сделать это.Спасибо за помощь !!!