第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

jest.runAllTimers() 拋出 TypeError

jest.runAllTimers() 拋出 TypeError

慕萊塢森 2023-04-20 16:58:24
我正在嘗試使用中的內(nèi)置react-scripts test腳本運(yùn)行以下測(cè)試create-react-app:Timer.test.jsrender(<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 似乎工作正常,直到它到達(dá)jest.runAllTimers(),當(dāng)我收到以下錯(cuò)誤時(shí): 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)我不知道發(fā)生了什么事。為什么它不能完成運(yùn)行測(cè)試?
查看完整描述

1 回答

?
慕田峪7331174

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超13個(gè)贊

你得到的錯(cuò)誤可能是因?yàn)閟etTimeout使用。setTimeout接受一個(gè)函數(shù)作為第一個(gè)參數(shù),但無(wú)論fireEvent.click(pauseButton). 將代碼更改為:


test('counts down when unpaused', async () => {

    jest.useFakeTimers();

    fireEvent.click(pauseButton)

    setTimeout(() =>  fireEvent.click(pauseButton), 1125);

            // ^ NOTE HERE

    jest.runAllTimers();

    expect(timerOutput).toHaveTextContent('24:59');

  })


查看完整回答
反對(duì) 回復(fù) 2023-04-20
  • 1 回答
  • 0 關(guān)注
  • 153 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)