Reputation: 425
I have a component that when created()
sets date:
with null
or with 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
}
}
In DevTools with no props
:
In DevTools with some props
:
When I do my test:
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')
})
})
I get this error:
Upvotes: 0
Views: 41
Reputation: 22393
created
only runs 1 time when component is created.
When you use setProps
, component props will be updated but created
method will not be called again.
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')
})
})
Upvotes: 1