cress-type

0.4.1 • Public • Published

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)

Readme

Keywords

none

Package Sidebar

Install

npm i cress-type

Weekly Downloads

1

Version

0.4.1

License

MIT

Last publish

Collaborators

  • xinchaobeta