Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
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.
jest-expect-jwt
Advanced tools
A nicer way to compare JWT properties in tests
toBeTokenContaining
It can be used to partially compare the object encoded within the token excluding the iat
or exp
.
If you want an exact match then use toBeTokenMatching
Example:
expect(token).toBeTokenContaining({ hello: "world" });
toBeTokenExpiringIn
Check when the token is expiring. This gives a couple of seconds leway either side to avoid having to mock dates. The expiry time can be written in a human readable format by using zeit/ms
Example:
expect(token).toBeExpiringIn("24h");
toBeTokenMatching
It can be used to exactly compare the object encoded within the token excluding the iat
or exp
.
If you want a partial match then use toBeTokenContaining
Example:
expect(token).toBeTokenMatching({ hello: "world" });
npm
npm install --save-dev jest-expect-jwt
yarn
yarn add --dev jest-expect-jwt
Add it your jest config either jest.config.js
or package.json
.
{
...
"setupFilesAfterEnv": ["jest-expect-jwt"],
...
}
If your editor does not detect the types then you can create a global.d.ts
with the contents as
below.
import "jest-expect-jwt";
FAQs
A nicer way to compare JWT properties in tests
The npm package jest-expect-jwt receives a total of 100 weekly downloads. As such, jest-expect-jwt popularity was classified as not popular.
We found that jest-expect-jwt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
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.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.