Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsinulhaq committed Nov 19, 2023
1 parent a8c422d commit 9d68305
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: macos-latest

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -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 }}
15 changes: 8 additions & 7 deletions tests/usePopperTooltip.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ beforeEach(() => {
vi.useFakeTimers();
});

afterEach(() => {
vi.runOnlyPendingTimers();
afterEach(async () => {
await vi.runOnlyPendingTimersAsync();
vi.useRealTimers();
});

Expand Down Expand Up @@ -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
Expand All @@ -213,14 +214,14 @@ test('delayHide option removes tooltip after specified delay', async () => {
render(<Tooltip options={{delayHide: 5000}} />);

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();
});
Expand Down

0 comments on commit 9d68305

Please sign in to comment.