component.spec.ts 1.2 KB

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