Vue-test-utils: error to pass required prop

Created on 25 Apr 2018  路  3Comments  路  Source: vuejs/vue-test-utils

Version

1.0.0-beta.15

Steps to reproduce

I have a component with item prop:

<template>
  <h2>{{ item.name }}</h2>
</template>

<script>
export default {
  name: 'CaseCard',
  props: {
    item: {
      type: Object,
      required: true
    }
  }
}
</script>

My prop item should be required, my test:

import { mount } from '@vue/test-utils'
import CaseCard from './CaseCard'

const cardsData = [
  { name: 'A', image: 'A', route: 'A', tags: ['A', 'AA']}
]

describe('CaseCard component', () => {
  test('render case name in h2 tag', () => {
    const component = mount(CaseCard, {
      propsData: {
        item: cardsData[0]
      }
    })
    const h2Tag = component.find('h2')

    expect(h2Tag.text()).toBe(cardsData[0].name)
  })

})

What is expected?

I think that it works and my test pass, but no works.

What is actually happening?

The error returned is: [Vue warn]: Missing required prop: "item"


If I remove required from my prop, the test pass, but I need use required.

All 3 comments

Sorry, the mistake was mine, I had not realized.

I get the same error. Any idea what fixed it?

your code has some error, in the same component or in parent or child components of it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jonyoder picture jonyoder  路  3Comments

yoyoys picture yoyoys  路  3Comments

matt-sanders picture matt-sanders  路  3Comments

maerteijn picture maerteijn  路  3Comments

josephstein picture josephstein  路  4Comments