From 9d683059a94c690a69640fd31f88773f0b62ed56 Mon Sep 17 00:00:00 2001 From: mohsinulhaq Date: Sun, 19 Nov 2023 14:25:33 +0530 Subject: [PATCH] fix tests --- .github/workflows/ci.yml | 5 +++-- tests/usePopperTooltip.spec.tsx | 15 ++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ee300ad..e265cd8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: macos-latest steps: - uses: actions/checkout@v4 @@ -41,6 +41,7 @@ jobs: pnpm build pnpm test pnpm lint - bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }} env: CI: true + - uses: codecov/codecov-action@v4: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/tests/usePopperTooltip.spec.tsx b/tests/usePopperTooltip.spec.tsx index 9beceff..972ef59 100644 --- a/tests/usePopperTooltip.spec.tsx +++ b/tests/usePopperTooltip.spec.tsx @@ -37,8 +37,8 @@ beforeEach(() => { vi.useFakeTimers(); }); -afterEach(() => { - vi.runOnlyPendingTimers(); +afterEach(async () => { + await vi.runOnlyPendingTimersAsync(); vi.useRealTimers(); }); @@ -198,10 +198,11 @@ test('delayShow option renders tooltip after specified delay', async () => { user.hover(screen.getByText(TriggerText)); // Nothing after a 2000ms - vi.advanceTimersByTime(2000); + await vi.advanceTimersByTimeAsync(2000); expect(screen.queryByText(TooltipText)).not.toBeInTheDocument(); - vi.runAllTimers(); + await vi.runAllTimersAsync(); + screen.debug(); // It shows up sometime later. Here RTL uses fake timers to await as well, so // it awaits for the element infinitely, advancing jest fake timer by 50ms // in an endless loop. And this is why the test passes even if delayShow set @@ -213,14 +214,14 @@ test('delayHide option removes tooltip after specified delay', async () => { render(); user.hover(screen.getByText(TriggerText)); - vi.runAllTimers(); + await vi.runAllTimersAsync(); expect(await screen.findByText(TooltipText)).toBeInTheDocument(); user.unhover(screen.getByText(TriggerText)); // Still present after 2000ms - vi.advanceTimersByTime(2000); + await vi.advanceTimersByTimeAsync(2000); expect(screen.getByText(TooltipText)).toBeInTheDocument(); - vi.runAllTimers(); + await vi.runAllTimersAsync(); // Removed some time later expect(screen.queryByText(TooltipText)).not.toBeInTheDocument(); });