我正在尝试使用中的内置react-scripts test脚本运行以下测试create-react-app:
Timer.test.js
render(<Timer />)
const pauseButton = screen.getByText('pause')
const timerOutput = screen.getAllByRole('heading')[1]
describe('Timer', () => {
test('renders Timer component', () => {
expect(screen.getByText(/session/i)).toBeInTheDocument()
expect(screen.getByText(/25/)).toBeInTheDocument()
})
test('counts down when unpaused', async () => {
jest.useFakeTimers()
fireEvent.click(pauseButton)
setTimeout(
fireEvent.click(pauseButton),
1125
)
jest.runAllTimers()
expect(timerOutput).toHaveTextContent('24:59')
})
})
Jest 似乎工作正常,直到它到达jest.runAllTimers(),当我收到以下错误时:
TypeError: callback.apply is not a function
23 | 1125
24 | )
> 25 | jest.runAllTimers()
| ^
26 | expect(timerOutput).toHaveTextContent('24:59')
27 | })
28 |
at node_modules/@jest/fake-timers/build/jestFakeTimers.js:524:25
at callback (node_modules/@jest/fake-timers/build/jestFakeTimers.js:516:29)
at FakeTimers._runTimerHandle (node_modules/@jest/fake-timers/build/jestFakeTimers.js:560:9)
at FakeTimers.runAllTimers (node_modules/@jest/fake-timers/build/jestFakeTimers.js:193:12)
at Object.<anonymous> (src/features/Timer.test.js:25:10)
我不知道发生了什么事。为什么它不能完成运行测试?
慕田峪7331174
相关分类