Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions packages/ui-checkbox/src/Checkbox/__tests__/Checkbox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,30 +279,28 @@ describe('<Checkbox />', () => {
})

describe('`toggle` variant', () => {
it('should expose a button role and pressed state', () => {
renderCheckbox({ variant: 'toggle', defaultChecked: true })
const toggle = screen.getByRole('button')
it('should expose a button role and pressed state', async () => {
await renderCheckbox({ variant: 'toggle', defaultChecked: true })
const toggle = page.getByRole('button').element()

expect(toggle).toHaveAttribute('aria-pressed', 'true')
expect(screen.queryByRole('checkbox')).not.toBeInTheDocument()
expect(page.getByRole('checkbox').query()).not.toBeInTheDocument()
})

it('should update the pressed state when toggled', async () => {
renderCheckbox({ variant: 'toggle', defaultChecked: false })
const toggle = screen.getByRole('button')
await renderCheckbox({ variant: 'toggle', defaultChecked: false })
const toggle = page.getByRole('button')

expect(toggle).toHaveAttribute('aria-pressed', 'false')
await expect.element(toggle).toHaveAttribute('aria-pressed', 'false')

await userEvent.click(toggle)
await userEvent.click(toggle, { force: true })

await waitFor(() => {
expect(toggle).toHaveAttribute('aria-pressed', 'true')
})
await expect.element(toggle).toHaveAttribute('aria-pressed', 'true')
})

it('should leave the `simple` variant as a checkbox', () => {
renderCheckbox({ variant: 'simple' })
const input = screen.getByRole('checkbox')
it('should leave the `simple` variant as a checkbox', async () => {
await renderCheckbox({ variant: 'simple' })
const input = page.getByRole('checkbox').element()

expect(input).not.toHaveAttribute('role')
expect(input).not.toHaveAttribute('aria-pressed')
Expand Down
Loading