我正在尝试配置 karma + mocha + should 但我必须遗漏一些东西,因为 should 在我的测试中未定义。
根据插件文档,要遵循的唯一步骤是:
1.- 在你的 karma 配置中添加 should 到 frameworks 和 karma-should 到 plugins 键:
module.exports = function(config) {
config.set({
frameworks: ['mocha', 'should'],
plugins: ['karma-should']
});
};
所有应该断言在测试中都可用
这是我的配置:
包.json
"devDependencies": {
"karma": "^0.13.3",
"karma-chrome-launcher": "^0.2.0",
"karma-firefox-launcher": "^0.1.6",
"karma-mocha": "^0.2.0",
"karma-phantomjs-launcher": "^0.2.0",
"karma-requirejs": "^0.2.2",
"karma-should": "0.0.1",
"mocha": "^2.2.5",
"should": "^7.0.2",
}
业力.conf.js
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha', 'should'],
plugins: ['karma-mocha',
'karma-should',
'karma-chrome-launcher',
'karma-firefox-launcher'],
简单测试.js
describe('theAnswer()', function() {
it('should be 42', function() {
theAnswer().should.be.exactly(42);
});
});
function theAnswer() {
return 42;
}
当我跑步时karma start
,我得到:
Firefox 39.0.0 (Windows 7 0.0.0) theAnswer() should be 42 FAILED
theAnswer(...).should is undefined
知道为什么吗?