小编Har*_*old的帖子

使用vue-test-utils为单元测试设置Vue计算属性

vue-test-utils提供了一个setComputed方法,允许您设置计算属性的状态.

import { mount } from '@vue/test-utils'
const wrapper = mount(Home)
wrapper.setComputed({loaded: true})
Run Code Online (Sandbox Code Playgroud)

vue-test-utils版本1.1.0.beta正在为读取的setComputed方法抛出弃用警告 setComputed() has been deprecated and will be removed in version 1.0.0. You can overwrite computed properties by passing a computed object in the mounting options

文档中安装选项未提及任何计算对象.我去了

const wrapper = mount(Home, { computed: {loaded: true} })
Run Code Online (Sandbox Code Playgroud)

const wrapper = mount(Home, {context: { computed: {loaded: true} }  })
Run Code Online (Sandbox Code Playgroud)

但那些爆炸了.

为vue-test-utils设置计算属性的方法是什么?

unit-testing vuejs2 vue-test-utils

7
推荐指数
2
解决办法
4689
查看次数

使用vue-test-utils配置过滤器

我们如何使用全局应用的过滤器配置组件安装?我认为这将是传递给createLocalVue的一些选项,但我在文档中没有看到它。

使用全局过滤器时,运行套件时在控制台中收到以下警告:

[Vue warn]: Failed to resolve filter: filterName
Run Code Online (Sandbox Code Playgroud)

wrapper.html()处的字符串包括预先计算的值,未应用过滤器,例如

{{ 'a string' | throughFilter }}
Run Code Online (Sandbox Code Playgroud)

还是

'a string'
Run Code Online (Sandbox Code Playgroud)

该过滤器可以在浏览器中工作,并且可以作为功能对其自身进行测试,但是我不想附带警告代码。

vue.js vue-component vue-test-utils

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