I'm attempting to focus on TDD with Typescript and so I built a new Vue project with the vue-cli (I selected to use Vue3, Typescript, and Jest). However when I ran the unit test out of the box it failed. After some investigation I found that the mount command from @vue/test-utils doesn't render any of the prop values:
HelloWorld.vue
<template>
<div class="hello">
<h1>{{ msg }}</h1>
{{ test }}
</div>
</template>
<script lang="ts">
import { Options, Vue } from "vue-class-component";
@Options({
props: {
msg: String,
}
})
export default class HelloWorld extends Vue {
msg!: string;
test: string = "It's a test";
}
</script>
example.specs.ts
import { mount } from "@vue/test-utils";
import HelloWorld from "@/components/HelloWorld.vue";
describe("HelloWorld.vue", () => {
it("renders props.msg when passed", async () => {
const msg = "new message";
const wrapper = mount(HelloWorld, {
props: { msg }
});
expect(wrapper.text()).toContain(msg);
});
});
When I print wrapper.html() I get the following:
<div class="hello" msg="new message"><h1></h1></div>
It doesn't seem to be rendering msg or test at all into the html. It has it listed as a prop, but that's about it.
I think one of the causes might be that I'm using a Typescript component instead of a traditional which might throw it off, but I'm not sure.
Any advice/tips?