比较 props 和数据的测试错误
Test Error Comparing Props and Data
我有一个组件,当 created()
将 date:
设置为 null
或 props.datainicial
。
export default {
props: ['numeroDaParcela', 'datainicial'],
data () {
return {
date: null,
dateBR: '',
modal: false
}
},
created () {
if (this.datainicial === '' ||
this.datainicial === undefined) {
this.date = null
} else {
this.date = this.datainicial
}
}
在没有 props
的 DevTools 中:
在 DevTools 中有一些 props
:
当我做测试时:
import { mount } from 'vue-test-utils'
import SelecionadorData from '@/components/Shared/SelecionadorData.vue'
describe('SelecionadorData.vue', () => {
it('should receive the props datainicial', () => {
const wrapper = mount(SelecionadorData)
wrapper.setProps({
datainicial: '2018-01-01'
})
expect(wrapper.vm.date).toBe('2018-01-01')
})
})
我收到这个错误:
created
仅在创建组件时运行 1 次。
当您使用 setProps
时,组件道具将被更新,但不会再次调用 created
方法。
import { mount } from 'vue-test-utils'
import SelecionadorData from '@/components/Shared/SelecionadorData.vue'
describe('SelecionadorData.vue', () => {
it('should receive the props datainicial', () => {
const wrapper = mount(SelecionadorData,
{
propsData: {
datainicial: '2018-01-01'
}
})
expect(wrapper.vm.date).toBe('2018-01-01')
})
})
我有一个组件,当 created()
将 date:
设置为 null
或 props.datainicial
。
export default {
props: ['numeroDaParcela', 'datainicial'],
data () {
return {
date: null,
dateBR: '',
modal: false
}
},
created () {
if (this.datainicial === '' ||
this.datainicial === undefined) {
this.date = null
} else {
this.date = this.datainicial
}
}
在没有 props
的 DevTools 中:
在 DevTools 中有一些 props
:
当我做测试时:
import { mount } from 'vue-test-utils'
import SelecionadorData from '@/components/Shared/SelecionadorData.vue'
describe('SelecionadorData.vue', () => {
it('should receive the props datainicial', () => {
const wrapper = mount(SelecionadorData)
wrapper.setProps({
datainicial: '2018-01-01'
})
expect(wrapper.vm.date).toBe('2018-01-01')
})
})
我收到这个错误:
created
仅在创建组件时运行 1 次。
当您使用 setProps
时,组件道具将被更新,但不会再次调用 created
方法。
import { mount } from 'vue-test-utils'
import SelecionadorData from '@/components/Shared/SelecionadorData.vue'
describe('SelecionadorData.vue', () => {
it('should receive the props datainicial', () => {
const wrapper = mount(SelecionadorData,
{
propsData: {
datainicial: '2018-01-01'
}
})
expect(wrapper.vm.date).toBe('2018-01-01')
})
})