tinobino / vue3-class-sfc-test Goto Github PK
View Code? Open in Web Editor NEWRepository to show not working Jest tests when using Vue SFC and vue-property-decorator.
Repository to show not working Jest tests when using Vue SFC and vue-property-decorator.
Hi there! I saw your comment in the vue-property-decorator issue, I'm currently struggling with unit tests for class components as well.
I also found that importing 'Vue' from 'vue-class-component' works, but only if you extend from it directly, so for instance this also fails:
<template>
<h1>ClassMain</h1>
<ClassChild />
{{ message }}
{{ greeting }}
</template>
<script lang="ts">
import ClassChild from "@/components/ClassChild.vue";
import TestMixin from "@/mixins/TestMixin.vue";
import { Options as Component, Vue, mixins } from "vue-class-component";
@Component({
components: {
ClassChild,
},
})
export default class ClassMain extends mixins(TestMixin) {
greeting = "Howdy!";
}
</script>
The mixin looks like this:
<script lang="ts">
import { Vue } from "vue-class-component";
export default class TestMixin extends Vue {
message = "Hello world!";
}
</script>
This results in 3 warnings:
[Vue warn]: Failed to resolve component: ClassChild
at <Anonymous ref="VTU_COMPONENT" >
at <VTUROOT>
[Vue warn]: Property "message" was accessed during render but is not defined on instance.
at <Anonymous ref="VTU_COMPONENT" >
at <VTUROOT>
[Vue warn]: Property "greeting" was accessed during render but is not defined on instance.
at <Anonymous ref="VTU_COMPONENT" >
at <VTUROOT>
I have no idea why this happens but I can't find many people that are having this issue so I thought it would atleast be good if you knew that it is not only happening with sub components. Basically anything you define in your class will not be available in a unit test if you dont extend Vue (which is imported from class-component) directly.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.