@@ -17,6 +17,7 @@ import { validateSlots } from './validate-slots'
1717import createScopedSlots from './create-scoped-slots'
1818import { createStubsFromStubsObject } from './create-component-stubs'
1919import { patchCreateElement } from './patch-create-element'
20+ import { isConstructor } from 'shared/validators'
2021
2122function vueExtendUnsupportedOption ( option : string ) {
2223 return `options.${ option } is not supported for ` +
@@ -39,13 +40,8 @@ export default function createInstance (
3940 options : Options ,
4041 _Vue : Component
4142) : Component {
42- // make sure all extends are based on this instance
43- _Vue . options . _base = _Vue
44-
4543 if (
46- VUE_VERSION < 2.3 &&
47- typeof component === 'function' &&
48- component . options
44+ VUE_VERSION < 2.3 && isConstructor ( component )
4945 ) {
5046 UNSUPPORTED_VERSION_OPTIONS . forEach ( ( option ) => {
5147 if ( options [ option ] ) {
@@ -54,11 +50,15 @@ export default function createInstance (
5450 } )
5551 }
5652
53+ let componentOptions = isConstructor ( component )
54+ ? component . options
55+ : component
56+
5757 // instance options are options that are passed to the
5858 // root instance when it's instantiated
5959 const instanceOptions = extractInstanceOptions ( options )
6060 const stubComponentsObject = createStubsFromStubsObject (
61- component . components ,
61+ componentOptions . components ,
6262 // $FlowIgnore
6363 options . stubs ,
6464 _Vue
@@ -69,31 +69,27 @@ export default function createInstance (
6969 addStubs ( _Vue , stubComponentsObject )
7070 patchCreateElement ( _Vue , stubComponentsObject , options . shouldProxy )
7171
72- if (
73- ( component . options && component . options . functional ) ||
74- component . functional
75- ) {
76- component = createFunctionalComponent ( component , options , _Vue )
72+ if ( componentOptions . functional ) {
73+ componentOptions = createFunctionalComponent (
74+ componentOptions ,
75+ options ,
76+ _Vue
77+ )
7778 } else if ( options . context ) {
7879 throwError (
7980 `mount.context can only be used when mounting a ` +
8081 `functional component`
8182 )
8283 }
8384
84- if ( componentNeedsCompiling ( component ) ) {
85- compileTemplate ( component )
85+ if ( componentNeedsCompiling ( componentOptions ) ) {
86+ compileTemplate ( componentOptions )
8687 }
8788
88- if ( component . options ) {
89- component . options . _base = _Vue
90- }
89+ // make sure all extends are based on this instance
90+ componentOptions . _base = _Vue
9191
92- // extend component from _Vue to add properties and mixins
93- // extend does not work correctly for sub class components in Vue < 2.2
94- const Constructor = typeof component === 'function'
95- ? _Vue . extend ( component . options ) . extend ( instanceOptions )
96- : _Vue . extend ( component ) . extend ( instanceOptions )
92+ const Constructor = _Vue . extend ( componentOptions ) . extend ( instanceOptions )
9793
9894 // used to identify extended component using constructor
9995 Constructor . options . $_vueTestUtils_original = component
@@ -122,8 +118,7 @@ export default function createInstance (
122118
123119 if ( options . parentComponent && ! isPlainObject ( options . parentComponent ) ) {
124120 throwError (
125- `options.parentComponent should be a valid Vue component ` +
126- `options object`
121+ `options.parentComponent should be a valid Vue component options object`
127122 )
128123 }
129124
0 commit comments