0

我一直使用 PhantomJS 作为浏览器来使用 grunt-karma 运行我的业力测试。我现在正在尝试切换到另一个浏览器,但是在运行测试时出现了各种各样的“无效 Chai 属性”错误,这似乎发生在使用应该断言的行上,例如“foo.should.be.a.function” ;" 我已经尝试了很多事情,但没有任何解决办法,而且似乎没有任何预先存在的问题可以解决这个问题。这是我的包和 karma.config。请注意,我已经缩短了这两个列表。我还应该补充一点,我已经尝试将所有与测试相关的模块更新到最新版本,因为我知道其中一些模块落后了几个版本,但这没有积极影响,所以我恢复了。

// karma.config
frameworks: ['mocha', 'chai', 'sinon-chai'],
browsers: ['ChromeHeadless'],

// package.json
"devDependencies": {
"angular-mocks": "1.6.5",
"babel-core": "6.26.0",
"babel-plugin-syntax-async-functions": "6.13.0",
"babel-plugin-transform-exponentiation-operator": "6.24.1",
"babel-plugin-transform-regenerator": "6.26.0",
"babel-preset-env": "1.6.1",
"chai": "4.1.2",
"chai-as-promised": "7.1.1",
"grunt": "1.0.1",
"grunt-angular-templates": "1.1.0",
"grunt-babel": "6.0.0",
"grunt-cli": "1.2.0",
"grunt-contrib-watch": "1.0.0",
"grunt-karma": "2.0.0",
"grunt-mocha-istanbul": "5.0.2",
"grunt-mocha-test": "0.13.2",
"include-all": "^4.0.3",
"istanbul": "0.4.5",
"karma": "1.7.1",
"karma-babel-preprocessor": "7.0.0",
"karma-chai": "0.1.0",
"karma-chrome-launcher": "2.2.0",
"karma-mocha": "1.3.0",
"karma-ng-html2js-preprocessor": "1.0.0",
"karma-phantomjs-launcher": "1.0.4",
"karma-sinon": "1.0.5",
"karma-sinon-chai": "1.3.4",
"karma-spec-reporter": "0.0.31",
"mocha": "3.2.0",
"sinon": "4.5.0",
"sinon-chai": "3.0.0",
"updtr": "2.0.0"

}

4

1 回答 1

0

在一些帮助下,我确定了我的问题。将 PhantomJS 与测试一起使用,例如

foo.should.be.a.function;

测试将毫无问题地通过,但我认为这是 PhantomJS 的错误,因为这不是此断言的正确语法。它应该是

foo.should.be.a('function');

在意识到这一点并进行所有更改后,Chrome 中的所有“无效 chai 属性”测试都通过了。PhantomJS 一直允许这些无效的测试运行,所以我很高兴我们正在做出改变。

于 2018-04-12T21:41:03.907 回答