-
Notifications
You must be signed in to change notification settings - Fork 14
/
useTitle.test.ts
54 lines (48 loc) · 1.46 KB
/
useTitle.test.ts
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
import { defineComponent, nextTick } from 'vue'
import { mount, VueWrapper } from '@vue/test-utils'
import { useTitle } from '../src/useTitle'
describe('test useTitle when restoreOnUnMount is true', () => {
let wrapper: VueWrapper<any>, setTitle: (title: string) => void
beforeEach(() => {
const comp = defineComponent({
template: '<div>test</div>',
setup () {
setTitle = useTitle('test', true)
}
})
document.title = 'init'
wrapper = mount(comp)
})
test('useTitle should be defined', () => {
expect(useTitle).toBeDefined()
})
test('document.title should be test after component mounted', () => {
expect(document.title).toBe('test')
})
test('document.title should change after invoking setTitle', (done) => {
setTitle('change')
nextTick(() => {
expect(document.title).toBe('change')
done()
})
})
test('document.title should be reset to init after component unmounted', () => {
wrapper.unmount()
expect(document.title).toBe('init')
})
})
describe('test useTitle when passing one parameter', () => {
test('document.title should not be reset to init when component is unmounted', () => {
const comp = defineComponent({
template: '<div>test</div>',
setup () {
useTitle('test')
}
})
document.title = 'init'
const wrapper = mount(comp)
expect(document.title).toBe('test')
wrapper.unmount()
expect(document.title).toBe('test')
})
})