2016-07-28 73 views
1

我目前正在嘗試爲我的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

有誰知道爲什麼會出現這個錯誤?

+1

也許你需要安裝[babel-plugin-transform-object-assign](https://babeljs.io/docs/plugins/transform-object-assign/) –

+0

@IsmailRBOUH - 這個工作!謝謝,你能寫這個作爲答案,我會投票嗎? – 30secondstosam

+0

答覆已添加;)歡迎您,祝您好運。 –

回答

0

您使用的是什麼版本的節點? Object.assign將始終不可用。您可能需要使用對象指派包

const assign = require('object-assign'); 
... 
this.options = assign({}, this.defauts, options) 
+0

錯誤來自測試上的控制檯,它抱怨我的javascript類中的行,而不是測試本身 – 30secondstosam

相關問題