Skip to content

Instantly share code, notes, and snippets.

@rjoydip-zz
Last active March 17, 2019 09:55
Show Gist options
  • Save rjoydip-zz/56c7fc3ec97ff06f06dc6b5780b3936c to your computer and use it in GitHub Desktop.
Save rjoydip-zz/56c7fc3ec97ff06f06dc6b5780b3936c to your computer and use it in GitHub Desktop.
test all keys of an array object

Test all keys of an array object using mocha, chai, chai-things.

Helper library

Chai Things

Note: Don't forgot to use chai.use(require('chai-things'));

Example:

// index.spec.ts
const chai = require('chai');
const obj = require('./index');

const expect = chai.expect;

chai.use(require('chai-things'));

describe('array obj test', () => {
    it('object type', () => {
        expect(typeof obj.data).equal('object');
    });
    it('object key check', () => {
        expect({
            status: 200,
            data: [{
                level: 6,
                points: 200,
                closing_ratios: 50,
                minimum_closing_ratios: 10,
                retention: 30
            }],
            message: 'Data Fetched Successfully successfully'
        }).to.have.all.deep.keys('level', 'points', 'closing_ratios', 'minimum_closing_ratios', 'retention');
    });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment