test(frontend): fix teleported toast assertions
This commit is contained in:
@@ -1,12 +1,24 @@
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import CardConverter from './CardConverter.vue'
|
||||
|
||||
enableAutoUnmount(afterEach)
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
function getAlert() {
|
||||
const alert = document.body.querySelector<HTMLElement>('[role="alert"]')
|
||||
|
||||
if (!alert) {
|
||||
throw new Error('Expected an alert to be rendered')
|
||||
}
|
||||
|
||||
return alert
|
||||
}
|
||||
|
||||
describe('CardConverter', () => {
|
||||
it('shows client validation without calling the API', async () => {
|
||||
const fetchMock = vi.fn()
|
||||
@@ -19,7 +31,7 @@ describe('CardConverter', () => {
|
||||
await wrapper.get('form').trigger('submit')
|
||||
|
||||
expect(fetchMock).not.toHaveBeenCalled()
|
||||
expect(wrapper.get('[role="alert"]').text()).toContain('۱۶ رقم')
|
||||
expect(getAlert().textContent).toContain('۱۶ رقم')
|
||||
})
|
||||
|
||||
it('renders the returned iban after a successful request', async () => {
|
||||
@@ -46,8 +58,6 @@ describe('CardConverter', () => {
|
||||
|
||||
expect(wrapper.text()).toContain('IR82 0540 1026 8002 0817 9090 02')
|
||||
expect(document.activeElement?.getAttribute('data-result')).toBe('iban')
|
||||
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('renders the safe API error message', async () => {
|
||||
@@ -74,8 +84,6 @@ describe('CardConverter', () => {
|
||||
await wrapper.get('form').trigger('submit')
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.get('[role="alert"]').text()).toContain(
|
||||
'تبدیل این شماره کارت انجام نشد.',
|
||||
)
|
||||
expect(getAlert().textContent).toContain('تبدیل این شماره کارت انجام نشد.')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user