Skip to content

Commit

Permalink
fix(test-utils): verify object not null for typeof (#1897)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ataias authored Oct 29, 2021
1 parent 19c2a64 commit dace7f1
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/server-test-utils/dist/vue-server-test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1806,7 +1806,7 @@ function isDynamicComponent(c) {
}

function isComponentOptions(c) {
return typeof c === 'object' && (c.template || c.render)
return c !== null && typeof c === 'object' && (c.template || c.render)
}

function isFunctionalComponent(c) {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function isDynamicComponent(c: any) {
}

export function isComponentOptions(c: any) {
return typeof c === 'object' && (c.template || c.render)
return c !== null && typeof c === 'object' && (c.template || c.render)
}

export function isFunctionalComponent(c: any) {
Expand Down
2 changes: 1 addition & 1 deletion packages/test-utils/dist/vue-test-utils.iife.js
Original file line number Diff line number Diff line change
Expand Up @@ -1953,7 +1953,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) {
}

function isComponentOptions(c) {
return typeof c === 'object' && (c.template || c.render)
return c !== null && typeof c === 'object' && (c.template || c.render)
}

function isFunctionalComponent(c) {
Expand Down
2 changes: 1 addition & 1 deletion packages/test-utils/dist/vue-test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1957,7 +1957,7 @@ function isDynamicComponent(c) {
}

function isComponentOptions(c) {
return typeof c === 'object' && (c.template || c.render)
return c !== null && typeof c === 'object' && (c.template || c.render)
}

function isFunctionalComponent(c) {
Expand Down
2 changes: 1 addition & 1 deletion packages/test-utils/dist/vue-test-utils.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -1956,7 +1956,7 @@
}

function isComponentOptions(c) {
return typeof c === 'object' && (c.template || c.render)
return c !== null && typeof c === 'object' && (c.template || c.render)
}

function isFunctionalComponent(c) {
Expand Down

0 comments on commit dace7f1

Please sign in to comment.