4

I am trying to test if the button press will call the Actions.sceneKey(); I've tried mocking it using

jest.mock(
  'react-native-router-flux', () => ({
    Actions: {
      sceneKey: jest.fn(),
    },
  })
);

but when this code runs:

test('enter received code', () => {
  const { getByPlaceholderText, getByText } = render(
    <EnterCode />
  );
  const button = getByText('confirm');
  fireEvent.press(button);
  expect(button).toBeTruthy();
  expect(Actions.sceneKey).toBeCalledTimes(1);
});

it says

expect(jest.fn()).toBeCalledTimes(expected)
Expected number of calls: 1
Received number of calls: 0
> 45 |   expect(Actions.sceneKey).toBeCalledTimes(1);

Also in my component I have this function in my onPress callback:

<Button
  onPress={() => {
    Actions.sceneKey();
    }}
  text="confirm"
/>

Also as I am new to testing a more important question is that do I even need to test the scene transition functions ?

skyboyer
  • 22,209
  • 7
  • 57
  • 64
Mohammad K.
  • 238
  • 3
  • 12

0 Answers0