代码之家  ›  专栏  ›  技术社区  ›  boardlemur

抑制单元测试中的Vue警告

  •  1
  • boardlemur  · 技术社区  · 7 年前

    我正试图按照下面列出的配置抑制测试中的警告: 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

    0 回复  |  直到 7 年前
        1
  •  3
  •   Ali Bahrami    7 年前

    根据VueJS文件- https://vue-test-utils.vuejs.org/api/config.html#silent

    类型:布尔型

    它在更改组件的 可观察物(如道具)。设置为false时,所有警告都可见 在控制台里。这是一种可配置的方式 这依赖于 Vue.config.silent文件

    ,所以您只需要导入 vue config.silent 到 false

    import Vue from `vue`
    Vue.config.silent = true;
    

    https://github.com/al1b/vue-test-utils-getting-started

    更多信息:

    如果你检查一下 source code

      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}`)
        }
      }
    
    推荐文章