javascript - ES6箭头函数TypeError : Cannot read property '1' of null with multiple params using Karma

标签 javascript angularjs ecmascript-6 karma-jasmine

我正尝试在 karma 中为 Angular 应用程序构建一些测试,并且我正在涉足 ES6。我正在尝试使用箭头函数而不是旧格式,但是当我尝试将具有多个参数的函数传递给注入(inject)函数时出现错误。

这很好用:

it('this is a test', () => {
    .....
});

这会抛出“TypeError:无法读取 null 的属性‘1’”:

it('this is another test',inject(($state, $q, $httpBackend)=> {
    ....
});

虽然这很好用:

it('this is another test',inject(function($state, $q, $httpBackend) {
    ....
});

有没有想过为什么会这样?非常感谢。

最佳答案

对于遇到此问题的其他人(https://xkcd.com/979),Angular(<1.5)注入(inject)与 ES6 箭头函数不兼容。升级或使用普通函数进行注入(inject)/模块。

它显然依赖于 toString 来获取参数名称,并且被箭头函数破坏了:/https://stackoverflow.com/a/32700361

关于javascript - ES6箭头函数TypeError : Cannot read property '1' of null with multiple params using Karma,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32912323/

相关文章:

javascript - Chrome 调试器中的 ES6 (React) 不起作用

javascript - 如何使用 es2015 模块打包库

javascript - 根据 redux 状态中的另一个值解构对象

javascript - 使用 immutable.js 操作 Redux 中嵌套数组中的数据

javascript - JQuery:如何使用 jQuery 检测移动宽度并将我的 css 更改为它?

angularjs - 为什么我在尝试在 AngularJS 中附加 HTML 时收到错误?

angularjs - 错误 : Graph container element not found

javascript - Webpack 和 angularJs

javascript - 悬停时向上滑动,悬停时向下滑动(没有独特的类别)

javascript - JS如何继续事件防止默认