When using the jest-expo
preset. I can’t seem to get modern
timers to work with waitfor
. Without the preset, it appears to work. Also it has been fixed with @testing-library/react-native as well, but the fix they have for the timer does not appear to work.
For example:
it("should work when starting at zero seconds", async () => {
jest
.useFakeTimers('modern')
.setSystemTime(new Date('2020-01-01T00:00:00Z').getTime());
const { getByTestId } = render(<MyComponent />)
await waitFor(() => {
expect(getByTestId("test").textContent).toEqual(new Date('2020-01-01T00:00:00Z').getTime().toString());
expect(renderCallback.mock.calls.length).toEqual(1);
});
// hangs at this point then does not complete the test.
For the time being I hacked up a solution with jest.config.js