Hereaは私の最初のテストです:
Heading.spec.js
import Vuetify from "vuetify";
import { shallowMount, createLocalVue } from "@vue/test-utils";
import router from "@/router";
import i18n from "@/locales";
import Heading from "@/components/Home/Heading.vue";
describe("Heading.vue", () => {
let wrapper;
beforeEach(() => {
const localVue = createLocalVue()
localVue.use(router)
localVue.use(Vuetify)
localVue.filter("translate", function(value) {
if (!value) return "";
value = "lang.views.global." + value.toString();
return i18n.t(value);
});
wrapper = shallowMount(Heading, { localVue: localVue, router, i18n });
});
it("should contains default heading", () => {
console.log ('WRAPPER: ', wrapper)
// const heading = wrapper.find("h1");
// expect(heading.text()).toContain("In the heart of Charentes...");
});
});
実行すると、Vuetifyでエラーが発生します...
console.log
vue-cli-service test:unit
PASS tests/unit/Heading.spec.js (11.247s)
Heading.vue
✓ should contains default heading (462ms)
console.log tests/unit/Heading.spec.js:23
WRAPPER: undefined
console.error node_modules/vuetify/dist/vuetify.js:19429
[Vuetify] Multiple instances of Vue detected
See https://github.com/vuetifyjs/vuetify/issues/4068
If you're seeing "$attrs is readonly", it's caused by this
console.error node_modules/vuetify/dist/vuetify.js:19429
[Vuetify] Multiple instances of Vue detected
See https://github.com/vuetifyjs/vuetify/issues/4068
If you're seeing "$attrs is readonly", it's caused by this
console.error node_modules/vue/dist/vue.runtime.common.js:589
[Vue warn]: Invalid prop: type check failed for prop "src". Expected String, got Object.
found in
---> <VParallax>
<Heading>
<Root>
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 17.641s
Ran all test suites.
Vue detected?
テストはパスしていますが、Vuetifyのエラーを理解していません。..フィードバックをありがとう
LocalVueを使用しないことで解決しました:
import Vue from "vue";
import { mount } from "@vue/test-utils";
import router from "@/router";
import Vuetify from "vuetify";
import i18n from "@/locales";
import Heading from "@/components/Home/Heading.vue";
describe("Heading.vue", () => {
let wrapper;
beforeEach(() => {
Vue.use(router);
Vue.use(Vuetify);
Vue.filter("translate", function(value) {
if (!value) return "";
value = "lang.views.global." + value.toString();
return i18n.t(value);
});
wrapper = mount(Heading, { router, i18n });
});
it('should have a happy ending', () => {
// You should see all Vuetify components properly rendered
// as normal HTML tags. For example, <v-flex> should be
// rendered as <div class="v-flex ...">
expect(wrapper.contains('div.flex')).toBe(true);
// Just so that you can visually inspect the rendered html.
console.log(wrapper.find('.subheading').html());
});
it("should contains default heading", () => {
const h1 = wrapper.find("h1");
expect(h1.is("h1")).toBe(true);
expect(h1.text()).toContain("In the heart of Charentes...");
});
});
更新:公式のVuetifyバグ への参照です Tristan Neumann の厚意によります。