chai-like
A JSON matcher for chai. This is really useful when you are testing API and want to ignore some attributes like: updatedAt, createdAt, id.
Install
Install with npm
npm install --save-dev chai-like
Assertions
like(value)
Compare two JSON and ignore some keys based on expectation.
var object = id: 1 name: 'test' updatedAt: 'now';objectshould;objectshouldnot;
Deeply compare.
var object = id: 1 name: 'test' product: id: 1 name: 'product' updatedAt: 'now';objectshould;objectshouldnot;
Compare array.
var array = id: 1 name: 'test' product: id: 1 name: 'product' updatedAt: 'now';arrayshould;arrayshouldnot;
Compare JSON with an array sub node.
var object = id: 1 name: 'test' products: id: 1 name: 'product' updatedAt: 'now';objectshould;objectshouldnot;
Plugins
You can extend chai-like with plugins as below format:
var chai = ;var like = ; var numberStringPlugin = { return !; } { return object === Numberexpected; };like; chai;
Then we can assert as below:
var object = number: 123 ; objectshould; objectshouldnot;
Plugin for testing strings with RegExp
If some strings require fuzzy matching we can do this with a plugin as follows:
var chai = ;var like = ; var regexPlugin = like; like; chai;
Then we can assert as below:
var object = text: 'the quick brown fox jumps over the lazy dog';objectshould;objectshouldnot;