Skip to content

Commit

Permalink
fix: make sure snackbar tests dont fail
Browse files Browse the repository at this point in the history
  • Loading branch information
Pagebakers committed Aug 4, 2022
1 parent cb48036 commit 305f799
Showing 1 changed file with 12 additions and 34 deletions.
46 changes: 12 additions & 34 deletions packages/saas-ui-snackbar/tests/use-snackbar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,33 @@
import * as React from 'react'
import { render, act, hooks, screen, waitFor } from '@saas-ui/test-utils'
import { render, screen } from '@saas-ui/test-utils'

import { useSnackbar } from '../src'

test('can accept shorthand options', async () => {
const title = 'Info'

const { result } = hooks.render(() => useSnackbar())

hooks.act(() => {
result.current.info(title)
})

const allByTitle = await screen.findAllByRole('alert', { name: title })

expect(allByTitle).toHaveLength(1)
})

test('can accept success handler', async () => {
const title = 'Success'

const { result } = hooks.render(() => useSnackbar())

hooks.act(() => {
result.current.success(title)
})

const allByTitle = await screen.findAllByRole('alert', { name: title })
const TestComponent = () => {
const snackbar = useSnackbar()

expect(allByTitle).toHaveLength(1)
})
return <button onClick={() => snackbar.info(title)}>Snackbar</button>
}

test('can accept error handler', async () => {
const title = 'Error'
const { user } = render(<TestComponent />)

const { result } = hooks.render(() => useSnackbar())
const button = await screen.findByText('Snackbar')
await user.click(button)

hooks.act(() => {
result.current.error(title)
const toast = await screen.findByRole('alert', {
name: title,
})

const allByTitle = await screen.findAllByRole('alert', { name: title })

expect(allByTitle).toHaveLength(1)
expect(toast).toBeInTheDocument()
})

it('should allow promise toast chainings', async () => {
const loadingTitle = 'Toast is loading'
const successTitle = 'Promise resolved'
const errorTitle = 'Error occurred'
const sleepTime = 200
const sleepTime = 500
const dummyPromise = new Promise<{ payload: string }>((r) =>
setTimeout(r, sleepTime, { payload: successTitle })
)
Expand Down

0 comments on commit 305f799

Please sign in to comment.