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 { afterEach, describe, expect, it, vi } from 'vitest'
|
||||||
|
|
||||||
import CardConverter from './CardConverter.vue'
|
import CardConverter from './CardConverter.vue'
|
||||||
|
|
||||||
|
enableAutoUnmount(afterEach)
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
vi.unstubAllGlobals()
|
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', () => {
|
describe('CardConverter', () => {
|
||||||
it('shows client validation without calling the API', async () => {
|
it('shows client validation without calling the API', async () => {
|
||||||
const fetchMock = vi.fn()
|
const fetchMock = vi.fn()
|
||||||
@@ -19,7 +31,7 @@ describe('CardConverter', () => {
|
|||||||
await wrapper.get('form').trigger('submit')
|
await wrapper.get('form').trigger('submit')
|
||||||
|
|
||||||
expect(fetchMock).not.toHaveBeenCalled()
|
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 () => {
|
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(wrapper.text()).toContain('IR82 0540 1026 8002 0817 9090 02')
|
||||||
expect(document.activeElement?.getAttribute('data-result')).toBe('iban')
|
expect(document.activeElement?.getAttribute('data-result')).toBe('iban')
|
||||||
|
|
||||||
wrapper.unmount()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('renders the safe API error message', async () => {
|
it('renders the safe API error message', async () => {
|
||||||
@@ -74,8 +84,6 @@ describe('CardConverter', () => {
|
|||||||
await wrapper.get('form').trigger('submit')
|
await wrapper.get('form').trigger('submit')
|
||||||
await flushPromises()
|
await flushPromises()
|
||||||
|
|
||||||
expect(wrapper.get('[role="alert"]').text()).toContain(
|
expect(getAlert().textContent).toContain('تبدیل این شماره کارت انجام نشد.')
|
||||||
'تبدیل این شماره کارت انجام نشد.',
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user