Skip to content

Commit

Permalink
Unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ananya-agarwal committed Mar 9, 2024
1 parent 3483c88 commit 59b9088
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,19 @@ describe('AlertComponent', () => {
expect(alertsAfterClosing[0]).toHaveTextContent('Error 1');
expect(alertsAfterClosing[1]).toHaveTextContent('Error 3');
});

test('info alerts should close automatically after 3 seconds', async () => {
render(<AlertComponent />);
expect(screen.queryAllByRole('alert')).toHaveLength(0);
act(() => huePubSub.publish('hue.global.info', { message: 'info' }));
expect(screen.queryAllByRole('alert')).toHaveLength(1);

//It should still be open after 2 seconds
jest.advanceTimersByTime(2000);
expect(screen.queryAllByRole('alert')).toHaveLength(1);

//After 3.1 seconds, it should really be closed
jest.advanceTimersByTime(1000);
expect(screen.queryAllByRole('alert')).toHaveLength(0);
});
});

0 comments on commit 59b9088

Please sign in to comment.