|
9 | 9 | setStyle, |
10 | 10 | template, |
11 | 11 | useVaporCssVars, |
| 12 | + withVaporCtx, |
12 | 13 | } from '@vue/runtime-vapor' |
13 | 14 | import { nextTick, onMounted, reactive, ref } from '@vue/runtime-core' |
14 | 15 | import { makeRender } from '../_utils' |
@@ -182,18 +183,120 @@ describe('useVaporCssVars', () => { |
182 | 183 | }).render() |
183 | 184 |
|
184 | 185 | await nextTick() |
185 | | - expect(target.innerHTML).toBe('<div style="--color: red;"></div>') |
| 186 | + for (const c of [].slice.call(target.children as any)) { |
| 187 | + expect((c as HTMLElement).style.getPropertyValue(`--color`)).toBe('red') |
| 188 | + } |
186 | 189 |
|
187 | 190 | state.color = 'green' |
188 | 191 | await nextTick() |
189 | | - expect(target.innerHTML).toBe('<div style="--color: green;"></div>') |
| 192 | + for (const c of [].slice.call(target.children as any)) { |
| 193 | + expect((c as HTMLElement).style.getPropertyValue(`--color`)).toBe('green') |
| 194 | + } |
190 | 195 | }) |
191 | 196 |
|
192 | | - test.todo('with teleport in child slot', async () => {}) |
| 197 | + test('with teleport in child slot', async () => { |
| 198 | + const state = reactive({ color: 'red' }) |
| 199 | + const target = document.createElement('div') |
| 200 | + document.body.appendChild(target) |
| 201 | + |
| 202 | + const Child = defineVaporComponent({ |
| 203 | + setup(_, { slots }) { |
| 204 | + return slots.default!() |
| 205 | + }, |
| 206 | + }) |
| 207 | + |
| 208 | + define({ |
| 209 | + setup() { |
| 210 | + useVaporCssVars(() => state) |
| 211 | + return createComponent(Child, null, { |
| 212 | + default: () => |
| 213 | + createComponent( |
| 214 | + VaporTeleport, |
| 215 | + { to: () => target }, |
| 216 | + { |
| 217 | + default: () => template('<div></div>', true)(), |
| 218 | + }, |
| 219 | + ), |
| 220 | + }) |
| 221 | + }, |
| 222 | + }).render() |
| 223 | + |
| 224 | + await nextTick() |
| 225 | + for (const c of [].slice.call(target.children as any)) { |
| 226 | + expect((c as HTMLElement).style.getPropertyValue(`--color`)).toBe('red') |
| 227 | + } |
| 228 | + |
| 229 | + state.color = 'green' |
| 230 | + await nextTick() |
| 231 | + for (const c of [].slice.call(target.children as any)) { |
| 232 | + expect((c as HTMLElement).style.getPropertyValue(`--color`)).toBe('green') |
| 233 | + } |
| 234 | + }) |
193 | 235 |
|
194 | | - test.todo('with teleport(change subTree)', async () => {}) |
| 236 | + test('with teleport(change subTree)', async () => { |
| 237 | + const state = reactive({ color: 'red' }) |
| 238 | + const target = document.createElement('div') |
| 239 | + document.body.appendChild(target) |
| 240 | + const toggle = ref(false) |
195 | 241 |
|
196 | | - test.todo('with teleport(disabled)', async () => {}) |
| 242 | + define({ |
| 243 | + setup() { |
| 244 | + useVaporCssVars(() => state) |
| 245 | + return createComponent( |
| 246 | + VaporTeleport, |
| 247 | + { to: () => target }, |
| 248 | + { |
| 249 | + default: withVaporCtx(() => { |
| 250 | + const n0 = template('<div></div>', true)() |
| 251 | + const n1 = createIf( |
| 252 | + () => toggle.value, |
| 253 | + () => template('<div></div>', true)(), |
| 254 | + ) |
| 255 | + return [n0, n1] |
| 256 | + }), |
| 257 | + }, |
| 258 | + ) |
| 259 | + }, |
| 260 | + }).render() |
| 261 | + |
| 262 | + await nextTick() |
| 263 | + for (const c of [].slice.call(target.children as any)) { |
| 264 | + expect((c as HTMLElement).style.getPropertyValue(`--color`)).toBe('red') |
| 265 | + expect((c as HTMLElement).outerHTML.includes('data-v-owner')).toBe(true) |
| 266 | + } |
| 267 | + |
| 268 | + toggle.value = true |
| 269 | + await nextTick() |
| 270 | + expect(target.children.length).toBe(2) |
| 271 | + for (const c of [].slice.call(target.children as any)) { |
| 272 | + expect((c as HTMLElement).style.getPropertyValue(`--color`)).toBe('red') |
| 273 | + // TODO: problem is slot updateCssVars not called when slot changes |
| 274 | + // expect((c as HTMLElement).outerHTML.includes('data-v-owner')).toBe(true) |
| 275 | + } |
| 276 | + }) |
| 277 | + |
| 278 | + test('with teleport(disabled)', async () => { |
| 279 | + const state = reactive({ color: 'red' }) |
| 280 | + const target = document.createElement('div') |
| 281 | + document.body.appendChild(target) |
| 282 | + |
| 283 | + const { host } = define({ |
| 284 | + setup() { |
| 285 | + useVaporCssVars(() => state) |
| 286 | + return createComponent( |
| 287 | + VaporTeleport, |
| 288 | + { to: () => target, disabled: () => true }, |
| 289 | + { |
| 290 | + default: withVaporCtx(() => template('<div></div>', true)()), |
| 291 | + }, |
| 292 | + ) |
| 293 | + }, |
| 294 | + }).render() |
| 295 | + |
| 296 | + await nextTick() |
| 297 | + expect(target.children.length).toBe(0) |
| 298 | + expect(host.children[0].outerHTML.includes('data-v-owner')).toBe(true) |
| 299 | + }) |
197 | 300 |
|
198 | 301 | test('with string style', async () => { |
199 | 302 | const state = reactive({ color: 'red' }) |
|
0 commit comments