简体   繁体   English

TypeError:超级表达式必须为null或函数

[英]TypeError: Super expression must either be null or a function

I'm very new to unit Testing in vue js. 我对vue js中的单元测试非常陌生。 I just went through this website to learn unit testing " https://vue-test-utils.vuejs.org/guides/#testing-single-file-components-with-mocha-webpack ". 我刚刚通过这个网站学习了单元测试“ https://vue-test-utils.vuejs.org/guides/#testing-single-file-components-with-mocha-webpack ”。 while I'm practicing the examples in "mocha-webpack" I got this Error 当我在“ mocha-webpack”中练习示例时,出现此错误

WEBPACK  Failed to compile with 1 error(s)
Error in ./src/Counter.vue
TypeError: Super expression must either be null or a function
at /opt/htdocs/guru/unitTest_prct/node_modules/prettier/index.js:32893:5
at /opt/htdocs/guru/unitTest_prct/node_modules/prettier/index.js:32913:4
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mdbvue@4.2.0 test: `mocha-webpack --webpack-config  webpack.config.js --require test/setup.js test/**/*.spec.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the mdbvue@4.2.0 test script.
npm ERR! This is probably not a problem with npm. There is likely     additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-09-06T10_28_47_073Z-debug.log

Can anyone tell me how to solve this error. 谁能告诉我如何解决此错误。 This is my Counter.vue file 这是我的Counter.vue文件

<template>
  <div>
   <div>
     {{ count }}
     <button @click="increment">Increment</button>
   </div>
  </div>
</template>

<script>
export default {
    data () {
       return {
         count: 0
       }
    },
   methods: {
      increment () {
        this.count++;
      }
    }
};
</script>

Here is my Counter.spec.js File 这是我的Counter.spec.js文件

import { shallowMount } from '@vue/test-utils'
import Counter from '../src/docs/Counter.vue'
describe('Counter.vue', () => {
  it('increments count when button is clicked', () => {
    const wrapper = shallowMount(Counter)
    wrapper.find('button').trigger('click')
    expect(wrapper.find('div').text()).toMatch('1')
  })
})

I've looked at the issue linked above . 我看了上面链接的问题

I have --require test/setup.js in the test script. 我在测试脚本中有--require test/setup.js Here's how it looks like: 看起来是这样的:

require('jsdom-global')();
window.Date = Date;

It solved the problem. 它解决了问题。 Try it out! 试试看!

It is a problem related with version 1.14.1 of prettier , that is a NPM package used in your scenario. 这是与1.14.1版本相关的问题prettier ,那就是在您的方案中使用的NPM包。

Indeed, looking at their GitHub repo the issue is reported. 确实,查看他们的GitHub存储库已报告了该问题。 At the moment there is a possible workaround: basically, it is to comment out line 32893 of prettier/index.js . 目前,有一个可能的解决方法:基本上是注释掉prettier prettier/index.js第32893行。

In your environment you can find the file here: /opt/htdocs/guru/unitTest_prct/node_modules/ . 在您的环境中,您可以在以下位置找到文件: /opt/htdocs/guru/unitTest_prct/node_modules/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型错误:超级表达式必须为空或反应本机中的函数_inherits - TypeError: Super expression must either be null or a function _inherits in react native 类型错误:超级表达式必须为空或函数 _inherits - TypeError: Super expression must either be null or a function _inherits TypeError:超级表达式必须为null或函数,且未定义 - TypeError: Super expression must either be null or a function, not undefined React Native,TypeError:超级表达式必须为空或函数 - React Native, TypeError: Super expression must either be null or a function TypeError:超级表达式必须是 null 或 React native 中的 function - TypeError: Super expression must either be null or a function in React native 超级表达式必须为null或函数,而不是对象 - Super expression must either be null or a function, not object nodejs 超级表达式必须是 null 或 function - nodejs Super expression must either be null or a function babel 或 webpack 或我的代码导致此错误“未捕获的类型错误:超级表达式必须是 null 或函数” - either babel or webpack or my code are causing this error "Uncaught TypeError: Super expression must either be null or a function" TypeError(“超级表达式必须是 null 或函数”) - 当 App 是 class 而不是 function 时 - TypeError(“Super expression must either be null or a function”) - when App is a class instead of a function 使用webpack的react-redux给出错误Uncaught TypeError:超级表达式必须为null或函数,且未定义 - react-redux with webpack giving error Uncaught TypeError: Super expression must either be null or a function, not undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM