MCPcopy
hub / github.com/vuejs/core / assertAnonymous

Function assertAnonymous

packages/runtime-core/__tests__/components/KeepAlive.spec.ts:753–802  ·  view source on GitHub ↗
(include: boolean)

Source from the content-addressed store, hash-verified

751 })
752
753 async function assertAnonymous(include: boolean) {
754 const one = {
755 name: 'one',
756 created: vi.fn(),
757 render: () => 'one',
758 }
759
760 const two = {
761 // anonymous
762 created: vi.fn(),
763 render: () => 'two',
764 }
765
766 const views: any = { one, two }
767 const viewRef = ref('one')
768
769 const App = {
770 render() {
771 return h(
772 KeepAlive,
773 {
774 include: include ? 'one' : undefined,
775 },
776 () => h(views[viewRef.value]),
777 )
778 },
779 }
780 render(h(App), root)
781
782 function assert(oneCreateCount: number, twoCreateCount: number) {
783 expect(one.created.mock.calls.length).toBe(oneCreateCount)
784 expect(two.created.mock.calls.length).toBe(twoCreateCount)
785 }
786
787 assert(1, 0)
788
789 viewRef.value = 'two'
790 await nextTick()
791 assert(1, 1)
792
793 viewRef.value = 'one'
794 await nextTick()
795 assert(1, 1)
796
797 viewRef.value = 'two'
798 await nextTick()
799 // two should be re-created if include is specified, since it's not matched
800 // otherwise it should be cached.
801 assert(1, include ? 2 : 1)
802 }
803
804 // 2.x #6938
805 test('should not cache anonymous component when include is specified', async () => {

Callers 1

KeepAlive.spec.tsFile · 0.85

Calls 5

renderFunction · 0.90
hFunction · 0.85
assertFunction · 0.70
refFunction · 0.50
nextTickFunction · 0.50

Tested by

no test coverage detected