blessing-skin-server/resources/assets/tests/scripts/toast.test.tsx

40 lines
922 B
TypeScript
Raw Normal View History

2020-02-04 12:23:14 +08:00
import React from 'react'
import { render } from '@testing-library/react'
import { Toast, ToastContainer } from '@/scripts/toast'
test('"Toast" class', () => {
render(<ToastContainer />)
const toast = new Toast()
toast.success('success')
expect(document.querySelector('.alert-success')!.textContent).toContain(
'success',
)
toast.info('info')
expect(document.querySelector('.alert-info')!.textContent).toContain('info')
toast.warning('warning')
expect(document.querySelector('.alert-warning')!.textContent).toContain(
'warning',
)
toast.error('error')
expect(document.querySelector('.alert-danger')!.textContent).toContain(
'error',
)
jest.runAllTimers()
})
2020-02-06 09:22:10 +08:00
test('clear toasts', () => {
render(<ToastContainer />)
const toast = new Toast()
toast.success('success')
toast.info('info')
toast.clear()
expect(document.querySelectorAll('.alert')).toHaveLength(0)
})