|
1 | 1 | import { type Ref, nextTick, onUpdated, ref } from '@vue/runtime-dom' |
2 | 2 | import { |
| 3 | + VaporTeleport, |
3 | 4 | createComponent, |
4 | 5 | createDynamicComponent, |
5 | 6 | createIf, |
@@ -256,130 +257,106 @@ describe('attribute fallthrough', () => { |
256 | 257 | expect(node.hasAttribute('foo')).toBe(false) |
257 | 258 | }) |
258 | 259 |
|
259 | | - // it('should not fallthrough with inheritAttrs: false', () => { |
260 | | - // const Parent = { |
261 | | - // render() { |
262 | | - // return h(Child, { foo: 1, class: 'parent' }) |
263 | | - // }, |
264 | | - // } |
265 | | - |
266 | | - // const Child = defineVaporComponent({ |
267 | | - // props: ['foo'], |
268 | | - // inheritAttrs: false, |
269 | | - // render() { |
270 | | - // return h('div', this.foo) |
271 | | - // }, |
272 | | - // }) |
273 | | - |
274 | | - // const root = document.createElement('div') |
275 | | - // document.body.appendChild(root) |
276 | | - // render(h(Parent), root) |
277 | | - |
278 | | - // // should not contain class |
279 | | - // expect(root.innerHTML).toMatch(`<div>1</div>`) |
280 | | - // }) |
281 | | - |
282 | | - // // #3741 |
283 | | - // it('should not fallthrough with inheritAttrs: false from mixins', () => { |
284 | | - // const Parent = { |
285 | | - // render() { |
286 | | - // return h(Child, { foo: 1, class: 'parent' }) |
287 | | - // }, |
288 | | - // } |
289 | | - |
290 | | - // const mixin = { |
291 | | - // inheritAttrs: false, |
292 | | - // } |
| 260 | + it('should not fallthrough with inheritAttrs: false', () => { |
| 261 | + const Parent = defineVaporComponent({ |
| 262 | + setup() { |
| 263 | + return createComponent(Child, { foo: () => 1, class: () => 'parent' }) |
| 264 | + }, |
| 265 | + }) |
293 | 266 |
|
294 | | - // const Child = defineVaporComponent({ |
295 | | - // mixins: [mixin], |
296 | | - // props: ['foo'], |
297 | | - // render() { |
298 | | - // return h('div', this.foo) |
299 | | - // }, |
300 | | - // }) |
| 267 | + const Child = defineVaporComponent({ |
| 268 | + props: ['foo'], |
| 269 | + inheritAttrs: false, |
| 270 | + setup(props) { |
| 271 | + const n0 = template('<div></div>', true)() as Element |
| 272 | + renderEffect(() => setElementText(n0, props.foo)) |
| 273 | + return n0 |
| 274 | + }, |
| 275 | + }) |
301 | 276 |
|
302 | | - // const root = document.createElement('div') |
303 | | - // document.body.appendChild(root) |
304 | | - // render(h(Parent), root) |
| 277 | + const { html } = define(Parent).render() |
305 | 278 |
|
306 | | - // // should not contain class |
307 | | - // expect(root.innerHTML).toMatch(`<div>1</div>`) |
308 | | - // }) |
| 279 | + // should not contain class |
| 280 | + expect(html()).toMatch(`<div>1</div>`) |
| 281 | + }) |
309 | 282 |
|
310 | | - // it('explicit spreading with inheritAttrs: false', () => { |
311 | | - // const Parent = { |
312 | | - // render() { |
313 | | - // return h(Child, { foo: 1, class: 'parent' }) |
314 | | - // }, |
315 | | - // } |
| 283 | + it('explicit spreading with inheritAttrs: false', () => { |
| 284 | + const Parent = defineVaporComponent({ |
| 285 | + setup() { |
| 286 | + return createComponent(Child, { foo: () => 1, class: () => 'parent' }) |
| 287 | + }, |
| 288 | + }) |
316 | 289 |
|
317 | | - // const Child = defineVaporComponent({ |
318 | | - // props: ['foo'], |
319 | | - // inheritAttrs: false, |
320 | | - // render() { |
321 | | - // return h( |
322 | | - // 'div', |
323 | | - // mergeProps( |
324 | | - // { |
325 | | - // class: 'child', |
326 | | - // }, |
327 | | - // this.$attrs, |
328 | | - // ), |
329 | | - // this.foo, |
330 | | - // ) |
331 | | - // }, |
332 | | - // }) |
| 290 | + const Child = defineVaporComponent({ |
| 291 | + props: ['foo'], |
| 292 | + inheritAttrs: false, |
| 293 | + setup(props, { attrs }) { |
| 294 | + const n0 = template('<div>', true)() as Element |
| 295 | + renderEffect(() => { |
| 296 | + setElementText(n0, props.foo) |
| 297 | + setDynamicProps(n0, [{ class: 'child' }, attrs]) |
| 298 | + }) |
| 299 | + return n0 |
| 300 | + }, |
| 301 | + }) |
333 | 302 |
|
334 | | - // const root = document.createElement('div') |
335 | | - // document.body.appendChild(root) |
336 | | - // render(h(Parent), root) |
| 303 | + const { html } = define(Parent).render() |
337 | 304 |
|
338 | | - // // should merge parent/child classes |
339 | | - // expect(root.innerHTML).toMatch(`<div class="child parent">1</div>`) |
340 | | - // }) |
| 305 | + // should merge parent/child classes |
| 306 | + expect(html()).toMatch(`<div class="child parent">1</div>`) |
| 307 | + }) |
341 | 308 |
|
342 | | - // it('should warn when fallthrough fails on non-single-root', () => { |
343 | | - // const Parent = { |
344 | | - // render() { |
345 | | - // return h(Child, { foo: 1, class: 'parent', onBar: () => {} }) |
346 | | - // }, |
347 | | - // } |
| 309 | + it('should warn when fallthrough fails on non-single-root', () => { |
| 310 | + const Parent = { |
| 311 | + setup() { |
| 312 | + return createComponent(Child, { |
| 313 | + foo: () => 1, |
| 314 | + class: () => 'parent', |
| 315 | + onBar: () => () => {}, |
| 316 | + }) |
| 317 | + }, |
| 318 | + } |
348 | 319 |
|
349 | | - // const Child = defineVaporComponent({ |
350 | | - // props: ['foo'], |
351 | | - // render() { |
352 | | - // return [h('div'), h('div')] |
353 | | - // }, |
354 | | - // }) |
| 320 | + const Child = defineVaporComponent({ |
| 321 | + props: ['foo'], |
| 322 | + render() { |
| 323 | + return [template('<div></div>')(), template('<div></div>')()] |
| 324 | + }, |
| 325 | + }) |
355 | 326 |
|
356 | | - // const root = document.createElement('div') |
357 | | - // document.body.appendChild(root) |
358 | | - // render(h(Parent), root) |
| 327 | + define(Parent).render() |
359 | 328 |
|
360 | | - // expect(`Extraneous non-props attributes (class)`).toHaveBeenWarned() |
361 | | - // expect(`Extraneous non-emits event listeners`).toHaveBeenWarned() |
362 | | - // }) |
| 329 | + expect(`Extraneous non-props attributes (class)`).toHaveBeenWarned() |
| 330 | + expect(`Extraneous non-emits event listeners`).toHaveBeenWarned() |
| 331 | + }) |
363 | 332 |
|
364 | | - // it('should warn when fallthrough fails on teleport root node', () => { |
365 | | - // const Parent = { |
366 | | - // render() { |
367 | | - // return h(Child, { class: 'parent' }) |
368 | | - // }, |
369 | | - // } |
370 | | - // const root = document.createElement('div') |
| 333 | + it.todo('should warn when fallthrough fails on teleport root node', () => { |
| 334 | + const Parent = { |
| 335 | + render() { |
| 336 | + return createComponent(Child, { class: () => 'parent' }) |
| 337 | + }, |
| 338 | + } |
371 | 339 |
|
372 | | - // const Child = defineVaporComponent({ |
373 | | - // render() { |
374 | | - // return h(Teleport, { to: root }, h('div')) |
375 | | - // }, |
376 | | - // }) |
| 340 | + const root = document.createElement('div') |
| 341 | + const Child = defineVaporComponent({ |
| 342 | + render() { |
| 343 | + // return h(Teleport, { to: root }, h('div')) |
| 344 | + return createComponent( |
| 345 | + VaporTeleport, |
| 346 | + { to: () => root }, |
| 347 | + { |
| 348 | + default: () => template('<div></div>')(), |
| 349 | + }, |
| 350 | + ) |
| 351 | + }, |
| 352 | + }) |
377 | 353 |
|
378 | | - // document.body.appendChild(root) |
379 | | - // render(h(Parent), root) |
| 354 | + document.body.appendChild(root) |
| 355 | + // render(h(Parent), root) |
| 356 | + define(Parent).render() |
380 | 357 |
|
381 | | - // expect(`Extraneous non-props attributes (class)`).toHaveBeenWarned() |
382 | | - // }) |
| 358 | + expect(`Extraneous non-props attributes (class)`).toHaveBeenWarned() |
| 359 | + }) |
383 | 360 |
|
384 | 361 | // it('should dedupe same listeners when $attrs is used during render', () => { |
385 | 362 | // const click = vi.fn() |
|
0 commit comments