You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

chai-match-pattern

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chai-match-pattern

Validates a deep structured JSON pattern

1.3.0
latest
Source
npm
Version published
Weekly downloads
166K
-0.91%
Maintainers
1
Weekly downloads
 
Created
Source

chai-match-pattern

NPM

Related Modules: lodash-match-pattern lodash-checkit

chai-match-pattern is a Swiss Army Knife for deep matching JSON objects. It is essentially a Chai wrapper for lodash-match-pattern and detailed documentation can be found there about its pattern matching functionality. This functionality includes deep matching of JSON properties by

  • Exact values
  • Regex
  • Any matcher from checkit (e.g. _.isURL, _.isEmail)
  • Any matcher from lodash (e.g. _.isObject, _.isNaN)
  • Partial matches
  • Custom matching functions
  • Filtered values
  • And more...
Basic Usage
# with npm
npm install chai-match-pattern --save-dev
# or with yarn
yarn add --dev chai-match-pattern

In your test file insert

const chai = require('chai');
const chaiMatchPattern = require('chai-match-pattern');
chai.use(chaiMatchPattern);
const _ = chaiMatchPattern.getLodashModule(); // recommend using our lodash extension

Then use patterns to check your JSON with the .matchPattern(pattern) assertion function. For example

chai.expect({a: 1, b: 'abc'}).to.matchPattern({a: 1, b: _.isString});

See lodash-match-pattern for way, way more details.

Additionally any of the included isXxxx functions can be used directly as assertion functions. For example

chai.expect(7.5).isBetween(7, 8);

Keywords

chai

FAQs

Package last updated on 17 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts