Skip to content

Commit dace7f1

Browse files
authored
fix(test-utils): verify object not null for typeof (#1897)
Using vue-test-utils may cause several messages of the sort ``` [Vue warn]: Error in render: "TypeError: Cannot read property 'template' of null" ``` Such messages stemmed from the `isComponentOptions` method call. It seems it received a null object and `typeof null` is object, so this error propagates to users of the library. This patch does not look for the reason a null object was sent in the first place, but it avoids the error propagation. close #1805
1 parent 19c2a64 commit dace7f1

File tree

5 files changed

+5
-5
lines changed

5 files changed

+5
-5
lines changed

packages/server-test-utils/dist/vue-server-test-utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,7 @@ function isDynamicComponent(c) {
18061806
}
18071807

18081808
function isComponentOptions(c) {
1809-
return typeof c === 'object' && (c.template || c.render)
1809+
return c !== null && typeof c === 'object' && (c.template || c.render)
18101810
}
18111811

18121812
function isFunctionalComponent(c) {

packages/shared/validators.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export function isDynamicComponent(c: any) {
8989
}
9090

9191
export function isComponentOptions(c: any) {
92-
return typeof c === 'object' && (c.template || c.render)
92+
return c !== null && typeof c === 'object' && (c.template || c.render)
9393
}
9494

9595
export function isFunctionalComponent(c: any) {

packages/test-utils/dist/vue-test-utils.iife.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1953,7 +1953,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) {
19531953
}
19541954

19551955
function isComponentOptions(c) {
1956-
return typeof c === 'object' && (c.template || c.render)
1956+
return c !== null && typeof c === 'object' && (c.template || c.render)
19571957
}
19581958

19591959
function isFunctionalComponent(c) {

packages/test-utils/dist/vue-test-utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1957,7 +1957,7 @@ function isDynamicComponent(c) {
19571957
}
19581958

19591959
function isComponentOptions(c) {
1960-
return typeof c === 'object' && (c.template || c.render)
1960+
return c !== null && typeof c === 'object' && (c.template || c.render)
19611961
}
19621962

19631963
function isFunctionalComponent(c) {

packages/test-utils/dist/vue-test-utils.umd.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1956,7 +1956,7 @@
19561956
}
19571957

19581958
function isComponentOptions(c) {
1959-
return typeof c === 'object' && (c.template || c.render)
1959+
return c !== null && typeof c === 'object' && (c.template || c.render)
19601960
}
19611961

19621962
function isFunctionalComponent(c) {

0 commit comments

Comments
 (0)