0👍
✅
It works for me after calling advanceTimersByTime
inside waitFor
.
describe.only('Vue Component (mobile) 2', () => {
beforeAll(() => {
isMobile.mockImplementation(() => true)
})
beforeEach(() => {
jest.useFakeTimers()
})
afterEach(() => {
jest.runOnlyPendingTimers()
jest.useRealTimers()
})
it('should render title after `props.delay` milliseconds', async () => {
const { queryByTestId } = myRender({
localVue: myMakeLocalVue(),
})
await waitFor(() => {
jest.advanceTimersByTime(5001)
})
expect(queryByTestId('modal-testid')).toBeVisible()
})
})
0👍
- remove this
jest.spyOn(global, 'setTimeout')
. jest will do it’s own magic with for this withuseFakeTimers
- I suppose you can not use
async
anddone
callback in one test case. Which version of jest do you use? - Add
await localVue.$nextTick()
afteradvanceTimersByTime
to wait until Vue apply all the changes
Source:stackexchange.com