как протестировать vuejs реквизитов с помощью Typescript + Jest - PullRequest
1 голос
/ 26 мая 2020

У меня есть следующая опора в одном файловом компоненте (Nuxt. js)

export default {
  props: {
    message: {
      type: String,
      required: true,
      validator: (value) => {
        return ['a', 'b', 'c'].includes(value)
      }
    }
  }
}

Я хотел бы протестировать все, что касается этого свойства message, поэтому я создал тест

Test.spec.js

it('should be required, a String and validates correctly', () => {
  const wrapper = shallowMount(Test, {
    propsData: {
      message: 'a',
    }
  })
  const messageProp = wrapper.vm.$options.props.message

  expect(messageProp.required).toBeTruthy()
  expect(messageProp.type).toBe(String)
  expect(messageProp.validator('a')).toBeTruthy()
  expect(messageProp.validator('x')).toBeFalsy()
})

Все работает отлично, без ошибок.

Но когда я пытаюсь сделать то же самое с Typescript (Nuxt. js + Машинопись)

<script lang="ts">
import Vue, { PropOptions } from 'vue'

export default Vue.extend({
  props: {
    message: {
      type: String,
      required: true,
      validator: (value) => {
        return ['a', 'b', 'c'].includes(value)
      }
    } as PropOptions<string>
  }
})
</script>

Я получаю эту ошибку Test.spec.ts

enter image description here

console.log(wrapper.vm.$options.props)

enter image description here

Может ли кто-нибудь помочь мне выполнить эту работу или лучший способ, чтобы я мог проверить все, что касается реквизита?

...