摩卡ES6 Babel“TypeError:undefined不是函数”
问题描述:
我目前正在尝试为我的JavaScript组件执行简单的测试,并从我的测试中得到错误:TypeError: undefined is not a function
。摩卡ES6 Babel“TypeError:undefined不是函数”
这示数上我的课中这一行:
this.options = Object.assign({}, this.defaults, options);
this.defaults
是默认选项的对象和options
是目前没有一个对象
我从运行代码CLI使用npm test
这可以解决这个问题:mocha ./src/components/myComponent/myComponent.spec.js --compilers js:babel-register
有谁知道为什么会出现这个错误?
答
您使用的是什么版本的节点? Object.assign将始终不可用。您可能需要使用对象指派包
const assign = require('object-assign');
...
this.options = assign({}, this.defauts, options)
+0
错误来自测试上的控制台,它抱怨我的javascript类中的行,而不是测试本身 – 30secondstosam
也许你需要安装[babel-plugin-transform-object-assign](https://babeljs.io/docs/plugins/transform-object-assign/) –
@IsmailRBOUH - 这个工作!谢谢,你能写这个作为答案,我会投票吗? – 30secondstosam
答复已添加;)欢迎您,祝您好运。 –