toaster.spec.js
2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { PortalTarget } from 'portal-vue'
import { mount } from '@vue/test-utils'
import { isVue3 } from '../../vue'
import { waitNT, waitRAF } from '../../../tests/utils'
import { BToaster } from './toaster'
describe('b-toaster', () => {
it('has expected structure', async () => {
const wrapper = mount(BToaster, {
attachTo: document.body,
propsData: {
name: 'foo'
}
})
expect(wrapper.vm).toBeDefined()
await waitNT(wrapper.vm)
await waitRAF()
expect(wrapper.element.tagName).toBe('DIV')
expect(wrapper.attributes('id')).toBe('foo')
expect(wrapper.attributes('aria-live')).toBeUndefined()
expect(wrapper.attributes('aria-atomic')).toBeUndefined()
expect(wrapper.attributes('role')).toBeUndefined()
expect(wrapper.classes()).toContain('b-toaster')
expect(wrapper.classes()).toContain('foo')
expect(wrapper.classes().length).toBe(2)
expect(wrapper.find('.b-toaster-slot').exists()).toBe(true)
const $slot = wrapper.find('.b-toaster-slot')
if (!isVue3) {
expect($slot.findComponent(PortalTarget).exists()).toBe(true)
}
expect($slot.element.tagName).toBe('DIV')
expect($slot.classes()).toContain('b-toaster-slot')
expect($slot.classes()).toContain('vue-portal-target')
expect($slot.classes().length).toBe(2)
expect($slot.text()).toEqual('')
wrapper.destroy()
})
it('accepts aria props', async () => {
const wrapper = mount(BToaster, {
attachTo: document.body,
propsData: {
name: 'bar',
ariaLive: 'assertive',
ariaAtomic: 'true',
role: 'alert'
}
})
expect(wrapper.vm).toBeDefined()
await waitNT(wrapper.vm)
await waitRAF()
expect(wrapper.element.tagName).toBe('DIV')
expect(wrapper.attributes('id')).toBe('bar')
expect(wrapper.attributes('aria-live')).toEqual('assertive')
expect(wrapper.attributes('aria-atomic')).toEqual('true')
expect(wrapper.attributes('role')).toEqual('alert')
expect(wrapper.find('.b-toaster-slot').exists()).toBe(true)
const $slot = wrapper.find('.b-toaster-slot')
if (!isVue3) {
expect($slot.findComponent(PortalTarget).exists()).toBe(true)
}
expect($slot.element.tagName).toBe('DIV')
expect($slot.classes()).toContain('b-toaster-slot')
expect($slot.classes()).toContain('vue-portal-target')
expect($slot.classes().length).toBe(2)
expect($slot.text()).toEqual('')
wrapper.destroy()
})
})