karma + mocha + should v7 不工作 - should 未定义
karma + mocha + should v7 not working - should is undefined
我正在尝试配置 karma + mocha + should,但我一定遗漏了一些东西,因为 should 在我的测试中未定义。
根据 plugin documentation,唯一需要遵循的步骤是:
1.- Add should to frameworks and karma-should to plugins keys in your
karma configuration:
module.exports = function(config) {
config.set({
frameworks: ['mocha', 'should'],
plugins: ['karma-should']
});
};
All should assertions are available in the tests
这是我的配置:
package.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",
}
karma.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'],
simpleTest.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
知道为什么吗?
由于 should 7.x.x:
中的包更改,这似乎是插件实现的问题
有一个开放的拉取请求:
https://github.com/seegno/karma-should/pull/1
当前插件版本 (0.0.1) 应该 6.x.x。
编辑: 最新的 karma-should 插件版本 (1.0.0) 纠正了这个问题。
我正在尝试配置 karma + mocha + should,但我一定遗漏了一些东西,因为 should 在我的测试中未定义。
根据 plugin documentation,唯一需要遵循的步骤是:
1.- Add should to frameworks and karma-should to plugins keys in your karma configuration:
module.exports = function(config) {
config.set({
frameworks: ['mocha', 'should'],
plugins: ['karma-should']
});
};
All should assertions are available in the tests
这是我的配置:
package.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",
}
karma.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'],
simpleTest.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
知道为什么吗?
由于 should 7.x.x:
中的包更改,这似乎是插件实现的问题有一个开放的拉取请求: https://github.com/seegno/karma-should/pull/1
当前插件版本 (0.0.1) 应该 6.x.x。
编辑: 最新的 karma-should 插件版本 (1.0.0) 纠正了这个问题。