Skip to content

Latest commit

 

History

History
47 lines (35 loc) · 847 Bytes

setProps.md

File metadata and controls

47 lines (35 loc) · 847 Bytes

setProps(props)

  • 引数:

    • {Object} props
  • 使用方法:

Wrapper vm プロパティを設定し更新を強制します。

Wrapper には Vue インスタンスを含む必要があることに注意してください

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

const wrapper = mount(Foo)
wrapper.setProps({ foo: 'bar' })
expect(wrapper.vm.foo).toBe('bar')

渡された値で Vue インスタンス を初期化する propsData オブジェクトを渡すことができます。

// Foo.vue
export default {
  props: {
    foo: {
      type: String,
      required: true
    }
  }
}
import { mount } from '@vue/test-utils'
import Foo from './Foo.vue'

const wrapper = mount(Foo, {
  propsData: {
    foo: 'bar'
  }
})

expect(wrapper.vm.foo).toBe('bar')