Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jest-expect-jwt

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-expect-jwt

A nicer way to compare JWT properties in tests

  • 1.0.1
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

jest-expect-jwt

A nicer way to compare JWT properties in tests

Expectations

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

Setup

1. Install the package

npm

npm install --save-dev jest-expect-jwt

yarn

yarn add --dev jest-expect-jwt

2. Configure it within jest

Add it your jest config either jest.config.js or package.json.

{
  ...
  "setupFilesAfterEnv": ["jest-expect-jwt"],
  ...
}

3. Typescript (optional)

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

Package last updated on 07 Mar 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc