This is an addon plugin for the Jest test framework, the chai assertion library and the should.js assertion library. It provides the most basic function type compare ability and tests.
Cress Type are available on npm.
$ npm install cress-type
In order to load the plugin, add Jest config option
to the package.json
file:
// package.json
...
"jest": {
"setupTestFrameworkScriptFile": "<rootDir>/node_modules/cress-type/dest/jest.js"
}
Then you can use it in Jest test files:
// __tests__/example.js
data1 = ['example', 1, {user: {name: 'cress', age: 99} }]
data2 = ['another example', 2, {user: {name: 'haha', age: 0}}]
expect(data1).toBeCompatible(data2)
var chai = require('chai')
, compatible = require('cress-type/dest/chai');
chai.use(compatible);
var should = chai.should()
, expect = chai.expect;
data1 = ['example', 1, {user: {name: 'cress', age: 99} }]
data2 = ['another example', 2, {user: {name: 'haha', age: 0}}]
//expect mode
expect(data1).to.be.compatible(data2)
//should mode
data1.should.be.compatible(data2)
var Should = require('should')
, compatible = require('cress-type/dest/should');
Should.use(compatible);
data1 = ['example', 1, {user: {name: 'cress', age: 99} }]
data2 = ['another example', 2, {user: {name: 'haha', age: 0}}]
data1.should.be.compatible(data2)
var compatible = require('cress-type');
data1 = ['example', 1, {user: {name: 'cress', age: 99} }]
data2 = ['another example', 2, {user: {name: 777, age: 0}}]
compatible(data1, data2)
//will output: {isCompatible: false, path: '[2].user.name'}
// which means
// typeof data1[2].user.name !== typeof data2[2].user.name
(The MIT License)