From cef7adc711eea3ea754e49cc6937d750627afce5 Mon Sep 17 00:00:00 2001 From: ilkin-overleaf <100852799+ilkin-overleaf@users.noreply.github.com> Date: Fri, 8 Apr 2022 14:01:10 +0300 Subject: [PATCH] Merge pull request #7480 from overleaf/ta-wait-for-test Add waitFor to fix flaky test GitOrigin-RevId: 3b0f0423e7126248383ba7c68556c9ae937f3533 --- .../frontend/shared/hooks/use-detach-layout.test.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/services/web/test/frontend/shared/hooks/use-detach-layout.test.js b/services/web/test/frontend/shared/hooks/use-detach-layout.test.js index 41d8c8abb1..359df11cf4 100644 --- a/services/web/test/frontend/shared/hooks/use-detach-layout.test.js +++ b/services/web/test/frontend/shared/hooks/use-detach-layout.test.js @@ -1,3 +1,4 @@ +import { waitFor } from '@testing-library/react' import { act } from '@testing-library/react-hooks' import { expect } from 'chai' import sinon from 'sinon' @@ -75,10 +76,11 @@ describe('useDetachLayout', function () { // check that all message were re-broadcast for the new tab await nextTick() // necessary to ensure all event handler have run - const reBroadcastMessagesCount = - sysendTestHelper.getAllBroacastMessages().length - expect(reBroadcastMessagesCount).to.equal(broadcastMessagesCount) - + await waitFor(() => { + const reBroadcastMessagesCount = + sysendTestHelper.getAllBroacastMessages().length + expect(reBroadcastMessagesCount).to.equal(broadcastMessagesCount) + }) // 3. simulate closed detached tab sysendTestHelper.spy.broadcast.resetHistory() sysendTestHelper.receiveMessage({