我试图按照此处列出的配置在测试中抑制警告:https://vue-test-utils.vuejs.org/api/config.html#silent https://vue-test-utils.vuejs.org/api/config.html#silent,如下:
import { config } from '@vue/test-utils';
// this should actually be the default but the default is not working
config.silent = true;
但是,我仍然在测试结果中看到警告:
TheQueue
✓ should show the queue bar if there are items queued
✓ should show the correct count of queued items in queued bar
[Vue warn]: Avoid mutating a prop directly since the value will be
overwritten whenever the parent component re-renders. Instead, use a
data or computed property based on the prop's value. Prop being
mutated: "mdTemplateData"
found in
---> <MdTab>
<MdContent>
<MdTabs>
<MdDrawer>
<TheQueue> at src/components/the-queue/TheQueue.vue
<Root>
值得注意的是,我在正常使用该应用程序时没有看到此错误。这仅在测试中弹出(否则我会尝试修复实际建议的问题)。
我在这里做错了什么以及为什么我不能抑制这些警告?或者我误解了什么silent
应该做什么?
根据 VueJS 文档 -https://vue-test-utils.vuejs.org/api/config.html#silent https://vue-test-utils.vuejs.org/api/config.html#silent
silent
类型:布尔值
默认值:true
它会在更改组件时抑制 Vue 触发的警告
可观察量(例如 props)。设置为 false 时,所有警告均可见
在控制台中。这是一种可配置的方式这依赖于
Vue.config.silent.
它依赖于 Vue.config.silent,所以你需要做的就是导入vue
打包并设置它的config.silent
to false
import Vue from `vue`
Vue.config.silent = true;
我在我的 Github 上放了一个工作示例,它只是官方示例的一个分支,但在测试期间不会显示警告。
https://github.com/al1b/vue-test-utils-getting-started https://github.com/al1b/vue-test-utils-getting-started
了解更多信息:
如果您检查源代码 https://github.com/vuejs/vue/blob/38e967b8067441ff37cb3b923200023a6b842759/src/core/util/debug.js#L23:
warn = (msg, vm) => {
const trace = vm ? generateComponentTrace(vm) : ''
if (config.warnHandler) {
config.warnHandler.call(null, msg, vm, trace)
} else if (hasConsole && (!config.silent)) {
console.error(`[Vue warn]: ${msg}${trace}`)
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)