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设置计算属性的方法是什么?
我们如何使用全局应用的过滤器配置组件安装?我认为这将是传递给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)
该过滤器可以在浏览器中工作,并且可以作为功能对其自身进行测试,但是我不想附带警告代码。