-
Notifications
You must be signed in to change notification settings - Fork 832
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Spinner test component (#1647)
Co-authored-by: Brandon Scott <[email protected]>
- Loading branch information
1 parent
6a76ed1
commit 0b3ba2d
Showing
2 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react' | ||
import { render, screen, act } from '@testing-library/react' | ||
import Spinner from '../src/Spinner' | ||
|
||
describe('Spinner', () => { | ||
jest.useFakeTimers() | ||
jest.spyOn(global, 'setTimeout') | ||
|
||
it('should not crash when rendering', () => { | ||
expect(() => { | ||
render(<Spinner />) | ||
}).not.toThrowError() | ||
}) | ||
|
||
it('should render', () => { | ||
render(<Spinner data-testid="Spinner" />) | ||
expect(screen.getByTestId('Spinner')).not.toBeNull() | ||
}) | ||
|
||
it('should render after delay time', () => { | ||
render(<Spinner delay={300} data-testid="Spinner-delay" />) | ||
|
||
act(() => { | ||
jest.advanceTimersByTime(300) | ||
}) | ||
|
||
expect(setTimeout).toHaveBeenCalledTimes(1) | ||
expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), 300) | ||
expect(screen.getByTestId('Spinner-delay')).not.toBeNull() | ||
}) | ||
}) |