-
Notifications
You must be signed in to change notification settings - Fork 646
Migrate PointerBox tests from Jest to Vitest with computed style assertions #6407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
92e3349
0169b57
98dbcb3
1927b89
b3ddae9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,56 +1,61 @@ | ||
| import {PointerBox} from '..' | ||
| import {render, behavesAsComponent, checkExports, renderStyles} from '../utils/testing' | ||
| import {render as HTMLRender} from '@testing-library/react' | ||
| import axe from 'axe-core' | ||
| import {describe, expect, it} from 'vitest' | ||
| import {render} from '@testing-library/react' | ||
| import {PointerBox, ThemeProvider} from '..' | ||
| import theme from '../theme' | ||
|
|
||
| describe('PointerBox', () => { | ||
| behavesAsComponent({Component: PointerBox}) | ||
|
|
||
| checkExports('PointerBox', { | ||
| default: PointerBox, | ||
| }) | ||
|
|
||
| it('renders a <Caret> in <Box> with relative positioning', () => { | ||
| expect(render(<PointerBox />)).toMatchSnapshot() | ||
| }) | ||
|
|
||
| it('should have no axe violations', async () => { | ||
| const {container} = HTMLRender(<PointerBox />) | ||
| const results = await axe.run(container) | ||
| expect(results).toHaveNoViolations() | ||
| expect(render(<PointerBox theme={theme} />)).toMatchSnapshot() | ||
| }) | ||
|
|
||
| it('applies the border color via "borderColor" prop for backwards compatibility', () => { | ||
| expect(render(<PointerBox borderColor="danger.emphasis" />)).toMatchSnapshot() | ||
| expect(render(<PointerBox borderColor="danger.emphasis" theme={theme} />)).toMatchSnapshot() | ||
|
||
| }) | ||
|
|
||
| it('applies the border color via sx prop', () => { | ||
| expect(render(<PointerBox sx={{borderColor: 'danger.emphasis'}} />)).toMatchSnapshot() | ||
| expect(render(<PointerBox sx={{borderColor: 'danger.emphasis'}} theme={theme} />)).toMatchSnapshot() | ||
|
||
| }) | ||
|
|
||
|
Check failure on line 18 in packages/react/src/PointerBox/PointerBox.test.tsx
|
||
| it('applies the background color via "bg" prop for backwards compatibility', () => { | ||
| expect(render(<PointerBox bg="danger.emphasis" />)).toMatchSnapshot() | ||
| expect( | ||
| render( | ||
| <ThemeProvider theme={theme}> | ||
| <PointerBox bg="danger.emphasis" /> | ||
| </ThemeProvider>, | ||
| ), | ||
| ).toMatchSnapshot() | ||
|
||
| }) | ||
|
|
||
| it('applies the background color via sx prop', () => { | ||
| expect(render(<PointerBox sx={{bg: 'danger.emphasis'}} />)).toMatchSnapshot() | ||
| expect( | ||
|
||
| render( | ||
| <ThemeProvider theme={theme}> | ||
|
Check failure on line 32 in packages/react/src/PointerBox/PointerBox.test.tsx
|
||
| <PointerBox sx={{bg: 'danger.emphasis'}} /> | ||
| </ThemeProvider>, | ||
| ), | ||
| ).toMatchSnapshot() | ||
| }) | ||
|
|
||
| it('ensures that background-color set via bg prop and sx output the same for backwards compatibility', () => { | ||
| const mockBg = 'red' | ||
| const viaStyledSystem = renderStyles(<PointerBox bg={mockBg} />) | ||
| const viaSxProp = renderStyles(<PointerBox sx={{bg: mockBg}} />) | ||
| expect(viaStyledSystem).toEqual( | ||
| expect.objectContaining({ | ||
| 'background-image': | ||
| 'linear-gradient(var(--custom-bg),var(--custom-bg)),linear-gradient(var(--bgColor-default,var(--color-canvas-default,#ffffff)),var(--bgColor-default,var(--color-canvas-default,#ffffff)))', | ||
| }), | ||
| const {container: containerBg} = render( | ||
| <ThemeProvider theme={theme}> | ||
| <PointerBox bg={mockBg} /> | ||
| </ThemeProvider>, | ||
| ) | ||
| expect(viaSxProp).toEqual( | ||
| expect.objectContaining({ | ||
| 'background-image': | ||
| 'linear-gradient(var(--custom-bg),var(--custom-bg)),linear-gradient(var(--bgColor-default,var(--color-canvas-default,#ffffff)),var(--bgColor-default,var(--color-canvas-default,#ffffff)))', | ||
| }), | ||
| const {container: containerSx} = render( | ||
|
Check failure on line 46 in packages/react/src/PointerBox/PointerBox.test.tsx
|
||
| <ThemeProvider theme={theme}> | ||
| <PointerBox sx={{bg: mockBg}} /> | ||
| </ThemeProvider>, | ||
| ) | ||
|
|
||
| const elementBg = containerBg.firstChild as HTMLElement | ||
| const elementSx = containerSx.firstChild as HTMLElement | ||
|
|
||
| // Both should have the same computed background styles | ||
| const stylesBg = window.getComputedStyle(elementBg) | ||
| const stylesSx = window.getComputedStyle(elementSx) | ||
|
|
||
| expect(stylesBg.backgroundImage).toBe(stylesSx.backgroundImage) | ||
| }) | ||
|
Check failure on line 60 in packages/react/src/PointerBox/PointerBox.test.tsx
|
||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the basic rendering snapshot test as requested. Commit b3ddae9