Invalid chai property when using Chrome, Firefox browsers in Karma

387 views Asked by At

I have been using PhantomJS as the browser to run my karma tests using grunt-karma. I am now trying to switch to another browser, but I am getting an assortment of "Invalid Chai property" errors when running the tests, which seem to happen on lines using should assertions, such as "foo.should.be.a.function;" I have tried a number of things, but nothing fixes it, and there doesn't seem to be any preexisting issues addressing this. Here is my package and karma.config. Note that I've shortened both lists. I should also add that I have tried updating all testing-related modules to their latest versions, since I know some of them are a couple versions behind, but this had no positive effect, so I reverted.

// 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"

}

1

There are 1 answers

0
Devin Fields On BEST ANSWER

With some help, I determined my issue. Using PhantomJS with tests such as

foo.should.be.a.function;

the test would pass without issue, but I believe this to be a fault of PhantomJS, since this is not the proper syntax for this assertion. It should be

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

After realizing this and making all the changes, all 'Invalid chai properties' tests passed in Chrome. PhantomJS has been allowing these invalid tests to run, so I am glad we are making the change.