Give Chai/Mocha a partial list of keys that should be included
chai, javascript, mocha.js, node.js, unit-testing
Solution
If you have an object like this one (similar to what you described):
var obj= {
user: "user",
title: "title",
content: "content",
message: "message"
};
all the following assertions should pass:
obj.should.include.keys(["user", "title", "content"]);
obj.should.includes.keys(["user", "title", "content"]);
obj.should.contain.keys(["user", "title", "content"]);
obj.should.includes.keys(["user", "title", "content"]);
even if you pass the values as separated arguments:
obj.should.include.keys("user", "title", "content");
obj.should.includes.keys("user", "title", "content");
obj.should.contain.keys("user", "title", "content");
obj.should.includes.keys("user", "title", "content");
So, assuming that you required `chai`'s `should` style correctly:
var should = require('chai').should();
, your problem may be just a typo in your `body` object or in your test suite.
UPDATE: After you added more information about the way you required all testing modules, a couple things should be pointed out:
First, you required `chai` two times, the second one when setting up `should`. You did:
var chai = require( 'chai' ),
should = require( 'chai' ).should(),
...
when you should've done:
var chai = require( 'chai' ),
should = chai.should(),
...
Second, if you're using `chai-as-promised`, you should assert `body` keys the way this module requires, like:
Promise.resolve(body).should.eventually.include.keys([ "user", "title", "content" ]);
Problem
It seems that if I do ``` describe( 'Add Youtube', function () { it( 'should return the video data, including user, title and content fields', function ( done ) { this.timeout( 5000 ) request({ method: 'POST', url: 'https://localhost:8443/api/add', json: true, strictSSL: false, body: { "type": "youtube", "url": "https://www.youtube.com/watch?v=uxfRLNiSikM" }, headers: { "Authorization": "Bearer " + newTestUser.token } }, function ( err, response, body ) { body.should.include.keys( [ "user", "title", "content" ] ) done() }) }) }) ``` That this will return an error since the object coming back also has the key `message`. How can I have this come back as passed as long as the 3 keys in the array are present, despite any more being there. I can't always predict what's going to be there in each case. UPDATE: Here is how I'm requiring Chai and `should`. ``` var chai = require( 'chai' ), chaiAsPromised = require( 'chai-as-promised' ), should = require( 'chai' ).should(), path = require( 'path' ), getUser = require( '../helpers/get-user' ), userController = require( '../controllers/userController' ), blogController = require( '../controllers/blogController' ), request = require( 'request' ), User = require( '../models/userModel' ), Content = require( '../models/contentModel' ), shortid = require( 'shortid' ) chai.use( chaiAsPromised ) ```