cress-type
v0.4.1
Published
detect whether one is similiar to another
Downloads
4
Readme
Cress Type
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.
Installation
Node.js
Cress Type are available on npm.
$ npm install cress-type
Usage
Use As a Jest Plug In
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)
Use As a Chai Plug In
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)
Use As a Should.js Plug In
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)
Use Not As Plug In
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
License
(The MIT License)