Reputation: 869
So I have this super simple Chai test that keeps failing for reasons I don't understand. Here is my code:
let chaiHttp = require('chai-http');
const helpers = require('../lib/helpers.js');
let chai = require('chai');
let should = chai.should();
chai.use(chaiHttp);
describe('Helper Functions', () => {
it('it should return an array of objects that represent the URL parameters passed in', function() {
const requestURL = {url: '/?designID=54w9G44aphaNHTvKg&labels=true&props=true'};
let parameters = helpers.getQueryParameters(requestURL);
(parameters).should.include.keys(['designID', 'labels', 'props']);
(parameters.designID).should.be.eql('54w9G44aphaNHTvKg');
(parameters.labels).should.be.eql('true');
(parameters.props).should.be.eql('true');
});
});
Everytime i try to test, I get the error TypeError: Cannot read property 'include' of undefined
If i comment out (parameters).should.include.keys(['designID', 'labels', 'props']);
, eveything passes. I haven't the slightest idea what is causing this...
When i console.log parameters, this is the object returned:
{
designID: '54w9G44aphaNHTvKg',
labels: 'true',
props: 'true'
}
UPDATE
So when i change the line to:
(JSON.parse(JSON.stringify(parameters))).should.have.keys(['designID', 'labels', 'props']);
Everything works fine... is there some kind of feature/bug that doesn't allow chai to read JSON unless it's properly formatted with double quotes?
Upvotes: 1
Views: 483