menu

Testing Library

Simple and complete DOM testing utilities that encourage good testing practices.

Channels
Chat
view-forward
# All channels
view-forward
# General
view-forward
# General Help
view-forward
# Angular Help
view-forward
# Cypress Help
view-forward
# DOM Help
view-forward
# React Help
view-forward
# TestCafe Help
view-forward
# Vue Help
view-forward
Team

Tests throwing async callback 5000ms timeout errors after upgrading to v9.4.0

February 21, 2020 at 8:06am

Tests throwing async callback 5000ms timeout errors after upgrading to v9.4.0

February 21, 2020 at 8:06am
In most of my unit tests I'm mocking the response of the axios async callback with jest. And the format is as follows:
test('Able to load page', async () => {
axiosInstance.get = jest.fn().mockResolvedValueOnce({
data: someData1
}).mockResolvedValueOnce({
data: someData2
})
const { getByText } = render(<Dashboard match={mockProps.match} auth={mockedAuth} />, { route: { pathname: '/page' } })
await wait(() => {
expect(getByText('Some Text')).toBeInTheDocument()
})
})
The above used to work with older versions of testing-library/react and now I'm facing failing tests due to Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.
I had to rewrite the awaiting elements to const el = await getByText('Some Text') in order for the tests to pass. But I'm curious as to why getBy* expect a promise like findBy* now? Shouldn't it be I need a await wait() to expect the element instead? Please help thanks!

February 21, 2020 at 8:24am
getBy query isn't returning a promise, so findBy query remains as the only async one. If const el = await getByText('Some Text') is working for you, it could mean you don't need to await for it because it's instantly available (as getByis sync).
  • reply
  • like