1. chai-match-pattern
Validates a deep structured JSON pattern
chai-match-pattern
Package: chai-match-pattern
Created by: mjhm
Last modified: Mon, 13 Jun 2022 05:51:07 GMT
Version: 1.3.0
License: MIT
Downloads: 265,491
Repository: https://github.com/mjhm/chai-match-pattern

Install

npm install chai-match-pattern
yarn add chai-match-pattern

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);

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin