Тестовая ошибка сравнения реквизита и данных - PullRequest
0 голосов
/ 18 мая 2018

У меня есть компонент, который, когда 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
    }
  }

В DevTools без props:

enter image description here

В DevTools с некоторыми props:

enter image description here

Когда я делаю свой тест:

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')
  })
})

Я получаю эту ошибку:

enter image description here

1 Ответ

0 голосов
/ 18 мая 2018

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')
  })
})
...