Jest/Vue: 注册组件

Jest/Vue: registering components

为什么我不能在我的 Jest 规范中挂载我的组件(为简洁起见,此处省略了大部分代码)?

# Photos.vue
<script>
  import Vue from 'vue'

  export default {
    name: 'photos'
    data: function () {
      ...
    }
  }
</script>

这是我的规格:

# Photos.test.js
import Vue from 'vue'
import { mount } from '@vue/test-utils'

Vue.component('photos', require('./Photos.vue').default)

describe('photos', () => {
  test('is a Vue instance', () => {
    const wrapper = mount(photos)
    expect(wrapper.isVueInstance()).toBeTruthy()
  })
})

这是错误:

ReferenceError: photos is not defined

   6 | describe('photos', () => {
   7 |   test('is a Vue instance', () => {
>  8 |     const wrapper = mount(photos)

你不能使用照片,因为你没有定义它。

# Photos.test.js
import Vue from 'vue'
import { mount } from '@vue/test-utils'

let photos = require('./Photos.vue')
Vue.component('photos', photos)

describe('photos', () => {
  test('is a Vue instance', () => {
    const wrapper = mount(photos)
    expect(wrapper.isVueInstance()).toBeTruthy()
  })
})