MCPcopy Create free account
hub / github.com/vuejs/test-utils / createInstance

Function createInstance

src/createInstance.ts:72–367  ·  view source on GitHub ↗
(
  // eslint-disable-next-line @typescript-eslint/no-empty-object-type
  inputComponent: DefineComponent<{}, {}, any, any, any, any>,
  options?: MountingOptions<any> & Record<string, any>
)

Source from the content-addressed store, hash-verified

70
71// implementation
72export function createInstance(
73 // eslint-disable-next-line @typescript-eslint/no-empty-object-type
74 inputComponent: DefineComponent<{}, {}, any, any, any, any>,
75 options?: MountingOptions<any> & Record<string, any>
76) {
77 // normalize the incoming component
78 const originalComponent = unwrapLegacyVueExtendComponent(inputComponent)
79 let component: ConcreteComponent
80 const instanceOptions = getInstanceOptions(options ?? {})
81
82 const rootComponents: CreateStubComponentsTransformerConfig['rootComponents'] =
83 {}
84
85 if (
86 isFunctionalComponent(originalComponent) ||
87 isLegacyFunctionalComponent(originalComponent)
88 ) {
89 component = defineComponent({
90 compatConfig: {
91 MODE: 3,
92 INSTANCE_LISTENERS: false,
93 INSTANCE_ATTRS_CLASS_STYLE: false,
94 COMPONENT_FUNCTIONAL: isLegacyFunctionalComponent(originalComponent)
95 ? 'suppress-warning'
96 : false
97 },
98 props: originalComponent.props || {},
99 setup:
100 (props, { attrs, slots }) =>
101 () =>
102 h(originalComponent, { ...props, ...attrs }, slots),
103 ...instanceOptions
104 })
105 rootComponents.functional = originalComponent
106 } else if (isObjectComponent(originalComponent)) {
107 component = { ...originalComponent, ...instanceOptions }
108 } else {
109 component = originalComponent
110 }
111
112 rootComponents.component = component
113 // We've just replaced our component with its copy
114 // Let's register it as a stub so user can find it
115 registerStub({ source: originalComponent, stub: component })
116
117 function slotToFunction(slot: Slot) {
118 switch (typeof slot) {
119 case 'function':
120 return slot
121 case 'object':
122 return () => h(slot)
123 case 'string':
124 return processSlot(slot)
125 default:
126 throw Error(`Invalid slot received.`)
127 }
128 }
129

Callers 2

mountFunction · 0.90
renderToStringFunction · 0.90

Calls 15

isFunctionalComponentFunction · 0.90
isObjectComponentFunction · 0.90
registerStubFunction · 0.90
mergeDeepFunction · 0.90
isDeepRefFunction · 0.90
mergeGlobalPropertiesFunction · 0.90
attachEmitListenerFunction · 0.90
isObjectFunction · 0.90
createVNodeTransformerFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…