componentSlots.spec.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { ref, render, h, nodeOps, nextTick } from '@vue/runtime-test'
  2. describe('component: slots', () => {
  3. // TODO more tests for slots normalization etc.
  4. test('should respect $stable flag', async () => {
  5. const flag1 = ref(1)
  6. const flag2 = ref(2)
  7. const spy = jest.fn()
  8. const Child = () => {
  9. spy()
  10. return 'child'
  11. }
  12. const App = {
  13. setup() {
  14. return () => [
  15. flag1.value,
  16. h(
  17. Child,
  18. { n: flag2.value },
  19. {
  20. foo: () => 'foo',
  21. $stable: true
  22. }
  23. )
  24. ]
  25. }
  26. }
  27. render(h(App), nodeOps.createElement('div'))
  28. expect(spy).toHaveBeenCalledTimes(1)
  29. // parent re-render, props didn't change, slots are stable
  30. // -> child should not update
  31. flag1.value++
  32. await nextTick()
  33. expect(spy).toHaveBeenCalledTimes(1)
  34. // parent re-render, props changed
  35. // -> child should update
  36. flag2.value++
  37. await nextTick()
  38. expect(spy).toHaveBeenCalledTimes(2)
  39. })
  40. })