Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@iotcomms.io/chai-json-pattern
Advanced tools
Deep matching objects with clear, JSON-like syntax.
Chai JSON pattern allows you to create blueprints for JavaScript objects to ensure validation of key information. It enables you to use JSON syntax extend with easy to use validators. It came up mostly for testing API with cucumber-js, but can be used in any application. Additionaly you can extend base functionality with custom validators. For more information see API reference.
See the detailed API Reference.
const pattern = `
{
"username": String AND alphanum AND minLength(3) AND maxLength(30),
"password": String AND regex("/^[0-9a-zA-Z]{5,30}$/"),
"access_token"?: String AND Number,
"birthyear": Integer AND range(1900, 2017),
"email": String,
...
}
`;
expect(user).to.matchPattern(pattern);
The above pattern require user
to be an object with keys that satisfy following conditions:
username
password
access_token
birthyear
email
If user
will not satisfy pattern, test will not pass, and you will see error with diff between user
and pattern.
Usage is a two steps process. First, you have to install chai-json-pattern
package.
npm install --save-dev chai-json-pattern
Then import chaiJsonPattern
and use matchPattern
:
import chai, { expect } from 'chai';
import chaiJsonPattern from 'chai-json-pattern';
chai.use(chaiJsonPattern);
expect({ a: 2 }).to.matchPattern(`{
"a": Number AND range(0, 5),
}`);
FAQs
Chai JSON pattern assertions
The npm package @iotcomms.io/chai-json-pattern receives a total of 855 weekly downloads. As such, @iotcomms.io/chai-json-pattern popularity was classified as not popular.
We found that @iotcomms.io/chai-json-pattern demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.