quasar 2.15.3 → 2.15.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/dist/api/AppFullscreen.json +1 -1
  2. package/dist/icon-set/bootstrap-icons.umd.prod.js +1 -1
  3. package/dist/icon-set/eva-icons.umd.prod.js +1 -1
  4. package/dist/icon-set/fontawesome-v5-pro.umd.prod.js +1 -1
  5. package/dist/icon-set/fontawesome-v5.umd.prod.js +1 -1
  6. package/dist/icon-set/fontawesome-v6-pro.umd.prod.js +1 -1
  7. package/dist/icon-set/fontawesome-v6.umd.prod.js +1 -1
  8. package/dist/icon-set/ionicons-v4.umd.prod.js +1 -1
  9. package/dist/icon-set/line-awesome.umd.prod.js +1 -1
  10. package/dist/icon-set/material-icons-outlined.umd.prod.js +1 -1
  11. package/dist/icon-set/material-icons-round.umd.prod.js +1 -1
  12. package/dist/icon-set/material-icons-sharp.umd.prod.js +1 -1
  13. package/dist/icon-set/material-icons.umd.prod.js +1 -1
  14. package/dist/icon-set/material-symbols-outlined.umd.prod.js +1 -1
  15. package/dist/icon-set/material-symbols-rounded.umd.prod.js +1 -1
  16. package/dist/icon-set/material-symbols-sharp.umd.prod.js +1 -1
  17. package/dist/icon-set/mdi-v3.umd.prod.js +1 -1
  18. package/dist/icon-set/mdi-v4.umd.prod.js +1 -1
  19. package/dist/icon-set/mdi-v5.umd.prod.js +1 -1
  20. package/dist/icon-set/mdi-v6.umd.prod.js +1 -1
  21. package/dist/icon-set/mdi-v7.umd.prod.js +1 -1
  22. package/dist/icon-set/svg-bootstrap-icons.umd.prod.js +1 -1
  23. package/dist/icon-set/svg-eva-icons.umd.prod.js +1 -1
  24. package/dist/icon-set/svg-fontawesome-v5.umd.prod.js +1 -1
  25. package/dist/icon-set/svg-fontawesome-v6.umd.prod.js +1 -1
  26. package/dist/icon-set/svg-ionicons-v4.umd.prod.js +1 -1
  27. package/dist/icon-set/svg-ionicons-v5.umd.prod.js +1 -1
  28. package/dist/icon-set/svg-ionicons-v6.umd.prod.js +1 -1
  29. package/dist/icon-set/svg-line-awesome.umd.prod.js +1 -1
  30. package/dist/icon-set/svg-material-icons-outlined.umd.prod.js +1 -1
  31. package/dist/icon-set/svg-material-icons-round.umd.prod.js +1 -1
  32. package/dist/icon-set/svg-material-icons-sharp.umd.prod.js +1 -1
  33. package/dist/icon-set/svg-material-icons.umd.prod.js +1 -1
  34. package/dist/icon-set/svg-material-symbols-outlined.umd.prod.js +1 -1
  35. package/dist/icon-set/svg-material-symbols-rounded.umd.prod.js +1 -1
  36. package/dist/icon-set/svg-material-symbols-sharp.umd.prod.js +1 -1
  37. package/dist/icon-set/svg-mdi-v6.umd.prod.js +1 -1
  38. package/dist/icon-set/svg-mdi-v7.umd.prod.js +1 -1
  39. package/dist/icon-set/svg-themify.umd.prod.js +1 -1
  40. package/dist/icon-set/themify.umd.prod.js +1 -1
  41. package/dist/lang/ar-TN.umd.prod.js +1 -1
  42. package/dist/lang/ar.umd.prod.js +1 -1
  43. package/dist/lang/az-Latn.umd.prod.js +1 -1
  44. package/dist/lang/bg.umd.prod.js +1 -1
  45. package/dist/lang/bn.umd.prod.js +1 -1
  46. package/dist/lang/ca.umd.prod.js +1 -1
  47. package/dist/lang/cs.umd.prod.js +1 -1
  48. package/dist/lang/da.umd.prod.js +1 -1
  49. package/dist/lang/de-CH.umd.prod.js +1 -1
  50. package/dist/lang/de-DE.umd.prod.js +1 -1
  51. package/dist/lang/de.umd.prod.js +1 -1
  52. package/dist/lang/el.umd.prod.js +1 -1
  53. package/dist/lang/en-GB.umd.prod.js +1 -1
  54. package/dist/lang/en-US.umd.prod.js +1 -1
  55. package/dist/lang/eo.umd.prod.js +1 -1
  56. package/dist/lang/es.umd.prod.js +1 -1
  57. package/dist/lang/et.umd.prod.js +1 -1
  58. package/dist/lang/eu.umd.prod.js +1 -1
  59. package/dist/lang/fa-IR.umd.prod.js +1 -1
  60. package/dist/lang/fa.umd.prod.js +1 -1
  61. package/dist/lang/fi.umd.prod.js +1 -1
  62. package/dist/lang/fr.umd.prod.js +1 -1
  63. package/dist/lang/gn.umd.prod.js +1 -1
  64. package/dist/lang/he.umd.prod.js +1 -1
  65. package/dist/lang/hi.umd.prod.js +1 -1
  66. package/dist/lang/hr.umd.prod.js +1 -1
  67. package/dist/lang/hu.umd.prod.js +1 -1
  68. package/dist/lang/id.umd.prod.js +1 -1
  69. package/dist/lang/is.umd.prod.js +1 -1
  70. package/dist/lang/it.umd.prod.js +1 -1
  71. package/dist/lang/ja.umd.prod.js +1 -1
  72. package/dist/lang/kk.umd.prod.js +1 -1
  73. package/dist/lang/km.umd.prod.js +1 -1
  74. package/dist/lang/ko-KR.umd.prod.js +1 -1
  75. package/dist/lang/kur-CKB.umd.prod.js +1 -1
  76. package/dist/lang/lt.umd.prod.js +1 -1
  77. package/dist/lang/lu.umd.prod.js +1 -1
  78. package/dist/lang/lv.umd.prod.js +1 -1
  79. package/dist/lang/mk.umd.prod.js +1 -1
  80. package/dist/lang/ml.umd.prod.js +1 -1
  81. package/dist/lang/mm.umd.prod.js +1 -1
  82. package/dist/lang/ms-MY.umd.prod.js +1 -1
  83. package/dist/lang/ms.umd.prod.js +1 -1
  84. package/dist/lang/my.umd.prod.js +1 -1
  85. package/dist/lang/nb-NO.umd.prod.js +1 -1
  86. package/dist/lang/nl.umd.prod.js +1 -1
  87. package/dist/lang/pl.umd.prod.js +1 -1
  88. package/dist/lang/pt-BR.umd.prod.js +1 -1
  89. package/dist/lang/pt.umd.prod.js +1 -1
  90. package/dist/lang/ro.umd.prod.js +1 -1
  91. package/dist/lang/ru.umd.prod.js +1 -1
  92. package/dist/lang/sk.umd.prod.js +1 -1
  93. package/dist/lang/sl.umd.prod.js +1 -1
  94. package/dist/lang/sm.umd.prod.js +1 -1
  95. package/dist/lang/sr-CYR.umd.prod.js +1 -1
  96. package/dist/lang/sr.umd.prod.js +1 -1
  97. package/dist/lang/sv.umd.prod.js +1 -1
  98. package/dist/lang/ta.umd.prod.js +1 -1
  99. package/dist/lang/th.umd.prod.js +1 -1
  100. package/dist/lang/tl.umd.prod.js +1 -1
  101. package/dist/lang/tr.umd.prod.js +1 -1
  102. package/dist/lang/ug.umd.prod.js +1 -1
  103. package/dist/lang/uk.umd.prod.js +1 -1
  104. package/dist/lang/uz-Cyrl.umd.prod.js +1 -1
  105. package/dist/lang/uz-Latn.umd.prod.js +1 -1
  106. package/dist/lang/vi.umd.prod.js +1 -1
  107. package/dist/lang/zh-CN.umd.prod.js +1 -1
  108. package/dist/lang/zh-TW.umd.prod.js +1 -1
  109. package/dist/quasar.cjs.prod.js +3 -3
  110. package/dist/quasar.esm.js +8 -7
  111. package/dist/quasar.esm.prod.js +3 -3
  112. package/dist/quasar.sass +1 -1
  113. package/dist/quasar.umd.js +8 -7
  114. package/dist/quasar.umd.prod.js +3 -3
  115. package/dist/web-types/web-types.json +1 -1
  116. package/package.json +3 -3
  117. package/src/components/toolbar/QToolbar.test.js +45 -0
  118. package/src/components/toolbar/QToolbarTitle.test.js +45 -0
  119. package/src/composables/use-interval/use-interval.test.js +173 -0
  120. package/src/composables/use-render-cache/use-render-cache.js +2 -2
  121. package/src/composables/use-render-cache/use-render-cache.test.js +73 -0
  122. package/src/composables/use-split-attrs/use-split-attrs.test.js +55 -0
  123. package/src/composables/use-tick/use-tick.test.js +118 -0
  124. package/src/composables/use-timeout/use-timeout.test.js +169 -0
  125. package/src/plugins/addressbar/AddressbarColor.test.js +53 -0
  126. package/src/plugins/app-fullscreen/AppFullscreen.json +3 -1
  127. package/src/plugins/app-fullscreen/AppFullscreen.test.js +206 -0
  128. package/src/plugins/app-fullscreen/test/mock-fullscreen.js +43 -0
  129. package/src/plugins/app-visibility/AppVisibility.test.js +45 -0
  130. package/src/plugins/dark/Dark.test.js +158 -0
  131. package/src/plugins/platform/Platform.js +2 -1
  132. package/src/plugins/private.body/Body.test.js +28 -0
  133. package/src/plugins/private.history/History.test.js +38 -0
  134. package/src/plugins/screen/Screen.test.js +453 -0
  135. package/src/utils/css-var/get-css-var.test.js +12 -0
  136. package/src/utils/css-var/set-css-var.test.js +18 -0
  137. package/src/utils/dom/dom.test.js +222 -0
  138. package/src/utils/private.render/render.test.js +187 -0
  139. package/src/utils/private.selection/selection.test.js +40 -0
  140. package/src/utils/private.vm/vm.test.js +175 -0
@@ -0,0 +1,222 @@
1
+ import { describe, test, expect, vi, onTestFinished } from 'vitest'
2
+ import { ref } from 'vue'
3
+
4
+ import dom, { getElement, childHasFocus } from './dom.js'
5
+
6
+ function createEl ({ top, left } = {}) {
7
+ const el = document.createElement('div')
8
+ el.setAttribute('tabindex', '0')
9
+ el.classList = 'fixed'
10
+
11
+ if (top !== void 0) {
12
+ el.style.top = top
13
+ }
14
+ if (left !== void 0) {
15
+ el.style.left = left
16
+ }
17
+
18
+ document.body.appendChild(el)
19
+ onTestFinished(() => { el.remove() })
20
+
21
+ return el
22
+ }
23
+
24
+ describe('[dom API]', () => {
25
+ describe('[Functions]', () => {
26
+ describe('[(function)offset]', () => {
27
+ test('has correct return value', () => {
28
+ const el = createEl()
29
+
30
+ expect(
31
+ dom.offset(el)
32
+ ).toStrictEqual({
33
+ top: expect.any(Number),
34
+ left: expect.any(Number)
35
+ })
36
+ })
37
+ })
38
+
39
+ describe('[(function)style]', () => {
40
+ test('has correct return value', () => {
41
+ const el = createEl({ top: '10px', left: '20px' })
42
+
43
+ expect(
44
+ dom.style(el, 'top')
45
+ ).toBe('10px')
46
+
47
+ expect(
48
+ dom.style(el, 'left')
49
+ ).toBe('20px')
50
+ })
51
+ })
52
+
53
+ describe('[(function)height]', () => {
54
+ test('height()', () => {
55
+ window.innerHeight = 100
56
+ expect(dom.height(window)).toBe(100)
57
+ })
58
+
59
+ test('height(el)', () => {
60
+ const el = createEl()
61
+ el.style.height = '100px'
62
+
63
+ expect(
64
+ dom.height(el)
65
+ ).toBeTypeOf('number')
66
+ })
67
+ })
68
+
69
+ describe('[(function)width]', () => {
70
+ test('width()', () => {
71
+ window.innerHeight = 100
72
+ expect(dom.height(window)).toBe(100)
73
+ })
74
+
75
+ test('width(el)', () => {
76
+ const el = createEl()
77
+ el.style.width = '100px'
78
+
79
+ expect(
80
+ dom.width(el)
81
+ ).toBeTypeOf('number')
82
+ })
83
+ })
84
+
85
+ describe('[(function)css]', () => {
86
+ test('has correct return value', () => {
87
+ const el = createEl()
88
+
89
+ const result = dom.css(el, {
90
+ width: '54px',
91
+ height: '154px'
92
+ })
93
+
94
+ expect(result).toBeUndefined()
95
+ expect(el.style.width).toBe('54px')
96
+ expect(el.style.height).toBe('154px')
97
+ })
98
+ })
99
+
100
+ describe('[(function)cssBatch]', () => {
101
+ test('has correct return value', () => {
102
+ const el1 = createEl()
103
+ const el2 = createEl()
104
+
105
+ const result = dom.cssBatch([ el1, el2 ], {
106
+ width: '54px',
107
+ height: '154px'
108
+ })
109
+
110
+ expect(result).toBeUndefined()
111
+
112
+ expect(el1.style.width).toBe('54px')
113
+ expect(el1.style.height).toBe('154px')
114
+
115
+ expect(el2.style.width).toBe('54px')
116
+ expect(el2.style.height).toBe('154px')
117
+ })
118
+ })
119
+
120
+ describe('[(function)ready]', () => {
121
+ test('ready()', () => {
122
+ expect(
123
+ dom.ready()
124
+ ).toBeUndefined()
125
+ })
126
+
127
+ test('ready(5)', () => {
128
+ expect(
129
+ dom.ready(5)
130
+ ).toBeUndefined()
131
+ })
132
+
133
+ test('ready(fn)', () => {
134
+ const fn = vi.fn(() => 5)
135
+
136
+ expect(
137
+ dom.ready(fn)
138
+ ).toBe(5)
139
+ })
140
+ })
141
+
142
+ describe('[(function)getElement]', () => {
143
+ test('getElement()', () => {
144
+ expect(getElement()).toBeUndefined()
145
+ })
146
+
147
+ test('getElement(null)', () => {
148
+ expect(getElement(null)).toBeUndefined()
149
+ })
150
+
151
+ test('getElement(el)', () => {
152
+ const el = createEl()
153
+ el.setAttribute('id', 'test-el')
154
+
155
+ expect(getElement('#test-el')).toBe(el)
156
+ expect(getElement('#bogus')).toBeUndefined()
157
+ })
158
+
159
+ test('getElement(vnode)', () => {
160
+ const el = createEl()
161
+ const vnode = { $el: el }
162
+
163
+ expect(getElement(vnode)).toBe(el)
164
+ })
165
+
166
+ test('getElement(ref)', () => {
167
+ const el = createEl()
168
+ const elRef = ref(el)
169
+
170
+ expect(getElement(elRef)).toBe(el)
171
+ })
172
+ })
173
+
174
+ describe('[(function)childHasFocus]', () => {
175
+ test('childHasFocus()', () => {
176
+ expect(childHasFocus()).toBe(true)
177
+ })
178
+
179
+ test('childHasFocus(null)', () => {
180
+ expect(childHasFocus(null)).toBe(true)
181
+ })
182
+
183
+ test('childHasFocus(el, elChild)', () => {
184
+ const el = createEl()
185
+ const elChild = document.createElement('div')
186
+ el.appendChild(elChild)
187
+
188
+ expect(
189
+ childHasFocus(el, elChild)
190
+ ).toBe(true)
191
+ })
192
+
193
+ test('childHasFocus(el, parentEl)', () => {
194
+ const parentEl = createEl()
195
+ const el = document.createElement('div')
196
+
197
+ expect(
198
+ childHasFocus(el, parentEl)
199
+ ).toBe(false)
200
+ })
201
+
202
+ test('childHasFocus(el, nextSiblingEl)', () => {
203
+ const el = createEl()
204
+ /* intermediateEl */ createEl()
205
+ const nextSiblingEl = createEl()
206
+
207
+ expect(
208
+ childHasFocus(el, nextSiblingEl)
209
+ ).toBe(true)
210
+ })
211
+
212
+ test('childHasFocus(el, prevSiblingEl)', () => {
213
+ const prevSiblingEl = createEl()
214
+ const el = createEl()
215
+
216
+ expect(
217
+ childHasFocus(el, prevSiblingEl)
218
+ ).toBe(false)
219
+ })
220
+ })
221
+ })
222
+ })
@@ -0,0 +1,187 @@
1
+ import { describe, test, expect } from 'vitest'
2
+ import { mount, flushPromises } from '@vue/test-utils'
3
+ import { ref } from 'vue'
4
+
5
+ import { hSlot, hUniqueSlot, hMergeSlot, hMergeSlotSafely, hDir } from './render.js'
6
+
7
+ describe('[render API]', () => {
8
+ describe('[Functions]', () => {
9
+ describe('[(function)hSlot]', () => {
10
+ test('hSlot()', () => {
11
+ expect(
12
+ hSlot()
13
+ ).toBeUndefined()
14
+ })
15
+
16
+ test('hSlot(void, x)', () => {
17
+ expect(
18
+ hSlot(void 0, 'x')
19
+ ).toBe('x')
20
+ })
21
+
22
+ test('hSlot(() => void, x)', () => {
23
+ expect(
24
+ hSlot(() => {}, 'x')
25
+ ).toBe('x')
26
+ })
27
+
28
+ test('hSlot(() => null, x)', () => {
29
+ expect(
30
+ hSlot(() => null, 'x')
31
+ ).toBe('x')
32
+ })
33
+
34
+ test('hSlot(() => z)', () => {
35
+ expect(
36
+ hSlot(() => 'z')
37
+ ).toBe('z')
38
+ })
39
+
40
+ test('hSlot(() => z, x)', () => {
41
+ expect(
42
+ hSlot(() => 'z', 'x')
43
+ ).toBe('z')
44
+ })
45
+ })
46
+
47
+ describe('[(function)hUniqueSlot]', () => {
48
+ test('hUniqueSlot()', () => {
49
+ expect(
50
+ hUniqueSlot()
51
+ ).toBeUndefined()
52
+ })
53
+
54
+ test('hUniqueSlot(void, x)', () => {
55
+ expect(
56
+ hUniqueSlot(void 0, 'x')
57
+ ).toBe('x')
58
+ })
59
+
60
+ test('hUniqueSlot(() => [z])', () => {
61
+ const value = [ 'z' ]
62
+ const result = hUniqueSlot(() => value)
63
+ expect(result).not.toBe(value)
64
+ expect(result).toStrictEqual([ 'z' ])
65
+ })
66
+
67
+ test('hUniqueSlot(() => [z], x)', () => {
68
+ const value = [ 'z' ]
69
+ const result = hUniqueSlot(() => value, 'x')
70
+ expect(result).not.toBe(value)
71
+ expect(result).toStrictEqual([ 'z' ])
72
+ })
73
+
74
+ test('hUniqueSlot(() => void, x)', () => {
75
+ expect(
76
+ hUniqueSlot(() => {}, 'x')
77
+ ).toBe('x')
78
+ })
79
+
80
+ test('hUniqueSlot(() => null, x)', () => {
81
+ expect(
82
+ hUniqueSlot(() => null, 'x')
83
+ ).toBe('x')
84
+ })
85
+ })
86
+
87
+ describe('[(function)hMergeSlot]', () => {
88
+ test('hMergeSlot(void, [x])', () => {
89
+ const source = [ 'x' ]
90
+ const result = hMergeSlot(void 0, source)
91
+ expect(result).toBe(source)
92
+ })
93
+
94
+ test('hMergeSlot(() => z, [x])', () => {
95
+ const source = [ 'x' ]
96
+ const result = hMergeSlot(() => 'z', source)
97
+ expect(result).not.toBe(source)
98
+ expect(result).toStrictEqual([ 'x', 'z' ])
99
+ })
100
+
101
+ test('hMergeSlot(() => [z], [x])', () => {
102
+ const source = [ 'x' ]
103
+ const result = hMergeSlot(() => [ 'z' ], source)
104
+ expect(result).not.toBe(source)
105
+ expect(result).toStrictEqual([ 'x', 'z' ])
106
+ })
107
+ })
108
+
109
+ describe('[(function)hMergeSlotSafely]', () => {
110
+ test('hMergeSlotSafely()', () => {
111
+ expect(hMergeSlot()).toBeUndefined()
112
+ })
113
+
114
+ test('hMergeSlotSafely(void, [x])', () => {
115
+ const source = [ 'x' ]
116
+ const result = hMergeSlotSafely(void 0, source)
117
+ expect(result).toBe(source)
118
+ })
119
+
120
+ test('hMergeSlotSafely(() => z, [x])', () => {
121
+ const source = [ 'x' ]
122
+ const result = hMergeSlotSafely(() => 'z', source)
123
+ expect(result).not.toBe(source)
124
+ expect(result).toStrictEqual([ 'x', 'z' ])
125
+ })
126
+
127
+ test('hMergeSlotSafely(() => [z], [x])', () => {
128
+ const source = [ 'x' ]
129
+ const z = [ 'z' ]
130
+ const result = hMergeSlotSafely(() => z, source)
131
+ expect(result).not.toBe(source)
132
+ expect(result).not.toBe(z)
133
+ expect(result).toStrictEqual([ 'x', 'z' ])
134
+ })
135
+
136
+ test('hMergeSlotSafely(() => [z])', () => {
137
+ const z = [ 'z' ]
138
+ const result = hMergeSlotSafely(() => z)
139
+ expect(result).toBe(z)
140
+ })
141
+ })
142
+
143
+ describe('[(function)hDir]', () => {
144
+ test('correctly mounts/unmounts directive', async () => {
145
+ let directiveIsMounted = false
146
+ const condition = ref(true)
147
+
148
+ const directive = {
149
+ name: 'custom-directive',
150
+ beforeMount () {
151
+ directiveIsMounted = true
152
+ },
153
+ beforeUnmount () {
154
+ directiveIsMounted = false
155
+ }
156
+ }
157
+
158
+ const wrapper = mount({
159
+ setup: () => {
160
+ return () => hDir(
161
+ 'div',
162
+ { class: 'div-class' },
163
+ [ 'child' ],
164
+ 'key',
165
+ condition.value,
166
+ () => [ [ directive ] ]
167
+ )
168
+ }
169
+ })
170
+
171
+ expect(directiveIsMounted).toBe(true)
172
+ expect(wrapper.html()).toBe('<div class="div-class">child</div>')
173
+
174
+ condition.value = false
175
+ await flushPromises()
176
+
177
+ expect(directiveIsMounted).toBe(false)
178
+ expect(wrapper.html()).toBe('<div class="div-class">child</div>')
179
+
180
+ condition.value = true
181
+ await flushPromises()
182
+ expect(directiveIsMounted).toBe(true)
183
+ expect(wrapper.html()).toBe('<div class="div-class">child</div>')
184
+ })
185
+ })
186
+ })
187
+ })
@@ -0,0 +1,40 @@
1
+ import { describe, test, expect, onTestFinished } from 'vitest'
2
+
3
+ import { clearSelection } from './selection.js'
4
+
5
+ describe('[selection API]', () => {
6
+ describe('[Functions]', () => {
7
+ describe('[(function)clearSelection]', () => {
8
+ test('has correct return value', () => {
9
+ expect(
10
+ clearSelection()
11
+ ).toBeUndefined()
12
+ })
13
+
14
+ test('works correctly', () => {
15
+ const selection = window.getSelection()
16
+
17
+ const el = document.createElement('div')
18
+ el.innerHTML = '<address>quasar@email.com</address>'
19
+
20
+ document.body.appendChild(el)
21
+
22
+ onTestFinished(() => { el.remove() })
23
+
24
+ selection.selectAllChildren(el)
25
+
26
+ expect(
27
+ selection.toString()
28
+ ).toBe('quasar@email.com')
29
+
30
+ expect(
31
+ clearSelection()
32
+ ).toBeUndefined()
33
+
34
+ expect(
35
+ selection.toString()
36
+ ).toBe('')
37
+ })
38
+ })
39
+ })
40
+ })
@@ -0,0 +1,175 @@
1
+ import { describe, test, expect } from 'vitest'
2
+ import { mount, flushPromises } from '@vue/test-utils'
3
+ import { h, getCurrentInstance } from 'vue'
4
+
5
+ import { getParentProxy, getNormalizedVNodes, vmHasRouter, vmIsDestroyed } from './vm.js'
6
+
7
+ import { getRouter } from 'testing/runtime/router.js'
8
+
9
+ describe('[vm API]', () => {
10
+ describe('[Functions]', () => {
11
+ describe('[(function)getParentProxy]', () => {
12
+ test('has correct return value', () => {
13
+ let childVm, parentVm
14
+
15
+ const ChildComponent = {
16
+ template: '<div />',
17
+ setup () {
18
+ childVm = getCurrentInstance()
19
+ return {}
20
+ }
21
+ }
22
+
23
+ mount({
24
+ template: '<div> <ChildComponent /> </div>',
25
+ components: {
26
+ ChildComponent
27
+ },
28
+ setup () {
29
+ parentVm = getCurrentInstance()
30
+ return {}
31
+ }
32
+ })
33
+
34
+ expect(
35
+ getParentProxy(childVm.proxy)
36
+ ).toBe(parentVm.proxy)
37
+ })
38
+
39
+ test('handles complex hierarchy', async () => {
40
+ let childVm, parentVm
41
+
42
+ const ChildComponent = {
43
+ template: '<div />',
44
+ setup () {
45
+ childVm = getCurrentInstance()
46
+ return {}
47
+ }
48
+ }
49
+
50
+ const IntermediateComponent = {
51
+ template: '<div> <ChildComponent /> </div>',
52
+ components: {
53
+ ChildComponent
54
+ }
55
+ }
56
+
57
+ mount({
58
+ template: '<div> <IntermediateComponent /> </div>',
59
+ components: {
60
+ IntermediateComponent
61
+ },
62
+ setup () {
63
+ parentVm = getCurrentInstance()
64
+ return {}
65
+ }
66
+ })
67
+
68
+ await flushPromises()
69
+
70
+ expect(
71
+ getParentProxy(
72
+ getParentProxy(childVm.proxy)
73
+ )
74
+ ).toBe(parentVm.proxy)
75
+ })
76
+ })
77
+
78
+ describe('[(function)getNormalizedVNodes]', () => {
79
+ test('has correct return value', () => {
80
+ let vnodes
81
+
82
+ const ParentComponent = {
83
+ setup (_, { slots }) {
84
+ return () => {
85
+ vnodes = getNormalizedVNodes(slots.default())
86
+ return h('div', {}, vnodes)
87
+ }
88
+ }
89
+ }
90
+
91
+ const ChildComponent = {
92
+ template: `
93
+ <div>
94
+ <div>Simple</div>
95
+ <div v-for="n in 2" :key="n">Child {{ n }}</div>
96
+ </div>
97
+ `
98
+ }
99
+
100
+ mount({
101
+ template: `
102
+ <ParentComponent>
103
+ <ChildComponent />
104
+ <ChildComponent v-for="n in 2" :key="n" />
105
+ </ParentComponent>
106
+ `,
107
+ components: {
108
+ ParentComponent,
109
+ ChildComponent
110
+ }
111
+ })
112
+
113
+ expect(vnodes).toBeDefined()
114
+ expect(vnodes).toHaveLength(3)
115
+ })
116
+ })
117
+
118
+ describe('[(function)vmHasRouter]', () => {
119
+ test('returns correctly with no router', () => {
120
+ let vm
121
+
122
+ mount({
123
+ template: '<div />',
124
+ setup () {
125
+ vm = getCurrentInstance()
126
+ return {}
127
+ }
128
+ })
129
+
130
+ expect(
131
+ vmHasRouter(vm)
132
+ ).toBe(false)
133
+ })
134
+
135
+ test('returns correctly with router', async () => {
136
+ let vm
137
+ const router = await getRouter('/route')
138
+
139
+ mount({
140
+ template: '<div />',
141
+ setup () {
142
+ vm = getCurrentInstance()
143
+ return {}
144
+ }
145
+ }, {
146
+ global: {
147
+ plugins: [ router ]
148
+ }
149
+ })
150
+
151
+ expect(
152
+ vmHasRouter(vm)
153
+ ).toBe(true)
154
+ })
155
+ })
156
+
157
+ describe('[(function)vmIsDestroyed]', () => {
158
+ test('has correct return value', () => {
159
+ let vm
160
+
161
+ const wrapper = mount({
162
+ template: '<div />',
163
+ setup () {
164
+ vm = getCurrentInstance()
165
+ return {}
166
+ }
167
+ })
168
+
169
+ expect(vmIsDestroyed(vm)).toBe(false)
170
+ wrapper.unmount()
171
+ expect(vmIsDestroyed(vm)).toBe(true)
172
+ })
173
+ })
174
+ })
175
+ })