If your tests are failing on GitHub Actions but pass locally, check the timeout of async functions, like waitFor()
(by default is 1000 ms).
Increase it to 5000 ms:
jsximport { render, screen, fireEvent, waitFor } from '@testing-library/react'; test('Some test', async () => { // Your code here... await waitFor(() => expect(screen.getByDisplayValue('Random')).toBeInTheDocument(), { timeout: 5000 }); });
To increase the timeout for all the functions in your tests, you can use the configure()
function:
jsximport { render, screen, fireEvent, waitFor } from '@testing-library/react'; import { configure } from '@testing-library/dom'; configure({ asyncUtilTimeout: 5000 }); test('Some test', async () => { // Your code here... await waitFor(() => expect(screen.getByDisplayValue('Random')).toBeInTheDocument()); });
Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.