Im trying to test when a user clicks a button and see if the function assign to that button is called. Im having problems because the function is an async function. Is there something wrong with the way Im testing it?
Function I want to test
const handlerFunction = useCallback(async () => {
await Storage.deleteKyes()l
A.reset();
navigate("Screen");
}, [navigate]);
return (
<Button
testID="btnChangeUser1"
data-testid="btnChangeUser1"
onPress={handlerFunction}
title={ChangeUser}
titleStyle={[t.fontSansSemiBold]}
/>
)
Testing method
describe("method should be called", () => {
it("Should activate when user press button ", async () => {
const handlerFunction = jest.fn();
const { getByText } = render(<ReactComponent />);
const element = getByText("ChangeUser");
fireEvent.press(element);
await waitFor(async () => {
await expect(handlerFunction).toHaveBeenCalled();
});
});
});
Error shown
expect(jest.fn()).toHaveBeenCalled()
Expected number of calls: >= 1
Received number of calls: 0
I know its an error with the async method, because if I remove the async and the await method everyting works
I tried changing the async calls made but nothing seems to work
Via Active questions tagged javascript - Stack Overflow https://ift.tt/v3fiK9q
Comments
Post a Comment