小编Ayo*_*oub的帖子

如何使用 jest 测试 nuxt.js 中的 head()

我使用 Nuxt.js 和 Jest 进行单元测试。我在布局中添加了一个 head 函数来更改标题,我想对其进行单元测试。这是我的文件:

<template>
  <h1 class="title">HELLO</h1>
</template>

<script>
export default {
  data () {
    return {
      title: 'MY TITLE'
    }
  },
  head () {
    return {
      title: this.title,
      meta: [
        { hid: 'description', name: 'description', content: 'MY DESCRIPTION' }
      ]
    }
  }
}
</script>
Run Code Online (Sandbox Code Playgroud)

我试过:

const wrapper = shallowMount(index)
wrapper.vm.head() <- fails
Run Code Online (Sandbox Code Playgroud)

有什么建议么?

unit-testing vue.js jestjs nuxt.js

3
推荐指数
1
解决办法
2769
查看次数

标签 统计

jestjs ×1

nuxt.js ×1

unit-testing ×1

vue.js ×1