Просмотр исходного кода

Merge pull request #14966 from overleaf/jpa-avoid-fake-clock

[web] avoid faking the clock in frontend tests

GitOrigin-RevId: 6fd5af54f1cbfa22901d24d47070fea097183394
Jakob Ackermann 3 лет назад
Родитель
Сommit
3383ec7908
1 измененных файлов с 4 добавлено и 9 удалено
  1. 4 9
      services/web/test/frontend/features/chat/components/chat-pane.test.js

+ 4 - 9
services/web/test/frontend/features/chat/components/chat-pane.test.js

@@ -12,7 +12,6 @@ import {
   cleanUpContext,
   cleanUpContext,
 } from '../../../helpers/render-with-context'
 } from '../../../helpers/render-with-context'
 import { stubMathJax, tearDownMathJaxStubs } from './stubs'
 import { stubMathJax, tearDownMathJaxStubs } from './stubs'
-import sinon from 'sinon'
 
 
 describe('<ChatPane />', function () {
 describe('<ChatPane />', function () {
   const user = {
   const user = {
@@ -22,16 +21,11 @@ describe('<ChatPane />', function () {
   }
   }
 
 
   beforeEach(function () {
   beforeEach(function () {
-    this.clock = sinon.useFakeTimers({
-      toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval'],
-    })
     window.metaAttributesCache = new Map()
     window.metaAttributesCache = new Map()
     window.metaAttributesCache.set('ol-user', user)
     window.metaAttributesCache.set('ol-user', user)
   })
   })
 
 
   afterEach(function () {
   afterEach(function () {
-    this.clock.runAll()
-    this.clock.restore()
     fetchMock.reset()
     fetchMock.reset()
     window.metaAttributesCache = new Map()
     window.metaAttributesCache = new Map()
   })
   })
@@ -98,12 +92,13 @@ describe('<ChatPane />', function () {
 
 
     renderWithChatContext(<ChatPane />, { user })
     renderWithChatContext(<ChatPane />, { user })
 
 
-    this.clock.tick(600) // wait for spinner to be displayed
+    // not displayed initially
+    expect(screen.queryByText('Loading…')).to.not.exist
 
 
+    // eventually displayed
     await screen.findByText('Loading…')
     await screen.findByText('Loading…')
 
 
-    this.clock.tick(1000) // wait for response to be received
-
+    // eventually removed when the fetch call returns
     await waitForElementToBeRemoved(() => screen.getByText('Loading…'))
     await waitForElementToBeRemoved(() => screen.getByText('Loading…'))
   })
   })