Open huuff opened 2 years ago
If you want to import interface
, it is recommended that you should write it in a separate .ts file
And then import it in a test
// ./types/index.ts
export interface TestProps {
input: string;
}
<template></template>
<script setup lang="ts">
import { TestProps } from './types'
const props = defineProps<TestProps>();
</script>
Then import them in a test
import { mount } from "@vue/test-utils";
import TestComponent from "./TestComponent.vue";
import { TestProps } from './types'
describe("TestComponent.vue", () => {
test("should compile", () => {
const wrapper = mount(TestComponent, {
props: { input: "test" },
})
})
});
Thanks for your answer. I tried this and got
[@vue/compiler-sfc] type argument passed to defineProps() must be a literal type, or a reference to an interface or literal type.
Are you sure this is possible? I though this open issue prevented it. I've uploaded a branch external_props
to my MCVE with your suggested changes and I'd be really grateful if you did a PR with whatever changes necessary to make it work
As of now this is not possible. The interface has to be in the same file. See Syntax Limitations in the vue documentation.
Version
5.0.0-rc.1
Reproduction link
github.com
Environment info
Steps to reproduce
Write a component that exports a type
Then try to import it in a test
See how it fails to compile with the following error:
What is expected?
The code compiles
What is actually happening?
It fails with
Note that these types of exports and imports work fine when running
npm run serve