Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot create component with shallowMount, vm.$refs['VTU_COMPONENT'] is not defined

Not sure if it is a bug or If I'm doing something wrong.

I try to mount my main App component with shallowMount but it doesn't works. I get the following error message:

Cannot set properties of undefined (setting 'hasOwnProperty')

It happens when vue-test-utils try to mount the App Component:

...
var appRef = vm.$refs[MOUNT_COMPONENT_REF];
// we add `hasOwnProperty` so jest can spy on the proxied vm without throwing
appRef.hasOwnProperty = function (property) {
    return Reflect.has(appRef, property);
};
console.warn = warnSave;
var wrapper = createVueWrapper(app, appRef, setProps);
trackInstance(wrapper);
return wrapper; 
...

Here, MOUNT_COMPONENT_REF equals 'VTU_COMPONENT' and vm.$refs[MOUNT_COMPONENT_REF] isn't defined.

Minimal example

It is available online : https://codesandbox.io/s/prod-glitter-tnoyqt?file=/src/App.spec.js

App.vue

<template>
  <div id="a-test">
    {{ test }}
  </div>
</template>

<script>
export default {
  name: "App",
};
</script>

App.spec.js

import { shallowMount } from "@vue/test-utils";
import App from "@/App";

describe("App.vue", () => {
  test("Test that fails", async () => {
    const wrapper = shallowMount(App);
  });
});
like image 509
snoob dogg Avatar asked Oct 26 '25 09:10

snoob dogg


1 Answers

fixed if I upgrade to @vue/test-utils 2.0.0-rc.21

like image 156
snoob dogg Avatar answered Oct 28 '25 23:10

snoob dogg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!