"[Vue warn]: Missing required prop" but default value is defined #7651
-
Hello, I'm testing with Vue 3.2.47, Vitest 0.28.4 and Happy DOM 8.2.6. I have several components with a required string property and a default value assigned and get this message in the terminal / console if the prop is not provided. However, it renders correctly in both the browser and happy DOM and the default value is used if I check in Devtools.
The unit test const properties = { ident: '42' }; // other props omitted for reasons
const wrapper = await mount(Widget, { props: properties });
// returns '42' and '2' the default value
const { ident, seats } = wrapper.props();
const widget = wrapper.get('.table-widget');
// both assertions pass
expect(widget.element.dataset.ident).toBe(properties.ident);
expect(widget.element.dataset.seats).toBe(seats); The component part // <script setup>
const stringRequired = {
type: String,
required: true,
};
const $props = defineProps({
ident: stringRequired,
seats: { ...stringRequired, default: '2' },
});
const compAttribs = {
'data-ident': $props.ident,
'data-seats': $props.seats,
}; <template>
<div ref="widget" v-bind="compAttribs"> </div>
</template>
<!-- eventually renders as expected -->
<div ref="widget" data-ident="42" data-seats="2"> </div> Why am I getting a Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Related to vuejs/vue#7720 |
Beta Was this translation helpful? Give feedback.
Related to vuejs/vue#7720