Babel/Karma/Chai提供TypeError:在严格模式功能下可能无法访问"caller","callee"和"arguments"属性 [英] Babel / Karma / Chai gives TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions

查看:101
本文介绍了Babel/Karma/Chai提供TypeError:在严格模式功能下可能无法访问"caller","callee"和"arguments"属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难弄清楚为什么这个测试没有通过.

I having trouble figuring out why this test is not passing.

var expect = require('chai').expect;

describe('HelloComponent', function() {

  it('passes a quite simple test', function() {
    expect(1 + 4).to.equal(5);
  });

});

产生此错误:

DEBUG [web-server]: serving: /Users/ivan/dev/react-starter/node_modules/karma/static/context.html
DEBUG [web-server]: serving (cached): /Users/ivan/dev/react-starter/node_modules/mocha/mocha.js
DEBUG [web-server]: serving (cached): /Users/ivan/dev/react-starter/node_modules/karma-mocha/lib/adapter.js
DEBUG [web-server]: serving (cached): /Users/ivan/dev/react-starter/test/front-end/tests.webpack.js
Chrome 41.0.2272 (Mac OS X 10.10.2) HelloComponent passes a quite simple test FAILED
        TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
            at new Assertion (/Users/ivan/dev/react-starter/test/front-end/tests.webpack.js:2166:43 <- webpack:///~/chai/lib/chai/assertion.js:33:42)
            at chai.expect (/Users/ivan/dev/react-starter/test/front-end/tests.webpack.js:3592:13 <- webpack:///~/chai/lib/chai/interface/expect.js:9:11)
            at Context.<anonymous> (/Users/ivan/dev/react-starter/test/front-end/tests.webpack.js:89:6 <- webpack:///test/front-end/hello-spec.js:10:4)

这可能与在严格模式下将babel包裹起来有关吗?

It might have something to do with babel wrapping things in strict mode?

有人知道我可以开始采取哪些步骤来弄清楚这里发生了什么吗?

Does anyone know what steps I can start to take to figure out what's going here?

该代码是开源的,可以在这里找到: https://github.com/UWFosterIT/react-starter/tree/gulp-webpack

The code is open source and available here: https://github.com/UWFosterIT/react-starter/tree/gulp-webpack

安装并重现此错误:

git clone https://github.com/UWFosterIT/react-starter.git
npm install
gulp test:karma

推荐答案

我正在使用babel和ES6模块. ES6代码是隐式严格模式. Chai的断言库与上面设置的严格模式不兼容.

I'm using babel and ES6 modules. ES6 code is implictly strict mode. Chai's assertion library is not compatible with strict mode as it's set up above.

解决方案是在webpack babel加载器中忽略/不包括node_modules:

The solution is to ignore / not include node_modules in the webpack babel loader:

这是我的karma.conf.js的相关部分:

This is the relevant section of my karma.conf.js:

webpack: {
  // any necessary webpack configuration
  devtool: 'inline-source-map',
  module: {
    loaders: [
      { test: /\.js$/, loader: 'babel', exclude: /node_modules/ }
    ]
  }
},

exclude是一个正则表达式测试,而不是简单的字符串.

The exclude is a regex test instead of a simple string.

这篇关于Babel/Karma/Chai提供TypeError:在严格模式功能下可能无法访问"caller","callee"和"arguments"属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆