Skip to content

Commit

Permalink
feature: Spinner test component (#1647)
Browse files Browse the repository at this point in the history
Co-authored-by: Brandon Scott <[email protected]>
  • Loading branch information
DevJoaoLopes and brandongregoryscott authored May 30, 2023
1 parent 6a76ed1 commit 0b3ba2d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
"prepublishOnly": "rm -rf esm commonjs umd types && yarn build",
"release": "np",
"size": "size-limit",
"storybook": "start-storybook -p 6006",
"test": "yarn lint && yarn tsd && yarn jest",
"test:coverage": "yarn jest --coverage",
"test:watch": "yarn jest --watch",
"typecheck": "tsc --noEmit",
"update-docs": "cd docs && yarn add evergreen-ui@latest --exact && git add package.json yarn.lock && git show-branch --no-name HEAD | grep -E 'v[0-9]+.[0-9]+.[0-9]+' && git commit --amend --no-edit || git commit -m \"Updated doc site evergreen version\""
Expand Down
31 changes: 31 additions & 0 deletions src/spinner/__tests__/Spinner.test.js
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()
})
})

0 comments on commit 0b3ba2d

Please sign in to comment.