I am trying to configure karma + mocha + should but I must be missing something since should is undefined in my tests.
According to the plugin documentation, the only steps to follow are:
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
This is my config:
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;
}
When I run karma start
I'm getting:
Firefox 39.0.0 (Windows 7 0.0.0) theAnswer() should be 42 FAILED
theAnswer(...).should is undefined
Any idea why??
It seems to be a problem with the plugin implementation due to a package change in should 7.x.x:
There's an open pull request for this: https://github.com/seegno/karma-should/pull/1
The current plugin version (0.0.1) works up to should 6.x.x.
EDIT: The latest karma-should plugin release (1.0.0) corrects this issue.