# chai-jwt

> JWT helpers for chai

Latest version **2.0.0** (published 2016-08-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install chai-jwt
pnpm add chai-jwt
yarn add chai-jwt
bun add chai-jwt
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2016-08-14 |
| First published | 2016-08-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/chai-jwt) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Damian Andres Fortuna |
| Maintainers | fortune |
| Keywords | jwt, jsonwebtoken |

## Links

- npm: https://www.npmjs.com/package/chai-jwt
- Repository: https://github.com/dafortune/chai-jwt
- Homepage: https://github.com/dafortune/chai-jwt#readme
- Issues: https://github.com/dafortune/chai-jwt/issues
- npm.io page: https://npm.io/package/chai-jwt

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.0.0 (latest) — 2016-08-14
- 1.0.0 — 2016-08-13

## README

# Chai-JWT
JSON Web tokens helpers for Chai

## Description
A set of helpers for chai that allow you to make assertions on
json web tokens.

## Installation
```
npm i chai-jwt
```

## Usage
```javascript
const chai = require('chai');
const chaiJWT = require('chai-jwt');

chai.use(chaiJWT);
```

## Assertions

### .jwt
Asserts that the provided string has a valid format that
can be parsed as JWT. *Does not check signature or the provided fields.*
If succeed, it changes the context to the decoded token.

Example
```javascript
  const validJWT = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzY29wZSI6InVwZGF0ZTpzb21ldGhpbmciLCJleHAiOjE0NzA3NjE3ODEsImlhdCI6MTQ3MDc2MDc5M30.1b4RC22Kpx4X4GWXU-Wgsk4IbeRGVD7tNW-tM-LzkVE';
  const invalidJWT = 'eyJ0eXAiOiJK22V1QiLCJhbGciOiJIUzI1NiJ9..1b4RC22Kpx4X4GWXU-Wgsk4IbeRGVD7tNW-tM-LzkVE';

  expect(validJWT).to.be.a.jwt; // Doesn't fail
  expect(invalidJWT).to.be.a.jwt; // fails

  expect(validJWT).to.be.a.jwt.and.eql({
    "scope": "update:something",
    "exp": 1470761781,
    "iat": 1470760793
  });
```

### .signedWith(secret)
Asserts that the provided token is signed with the provided secret.

Example
```javascript
  const validJWT = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzY29wZSI6InVwZGF0ZTpzb21ldGhpbmciLCJleHAiOjE0NzA3NjE3ODEsImlhdCI6MTQ3MDc2MDc5M30.1b4RC22Kpx4X4GWXU-Wgsk4IbeRGVD7tNW-tM-LzkVE';

  expect(validJWT).to.be.signedWith('1234'); // Doesn't fail
  expect(validJWT).to.be.signedWith('not the right secret'); // fails
```

### .claim(key, [value])
Alias of `.property` for JWTs. Asserts that the provided token has a given claim. If value is provided
it will also assert the claim value using strict equality.

Example
```javascript
  const validJWT = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzY29wZSI6InVwZGF0ZTpzb21ldGhpbmciLCJleHAiOjE0NzA3NjE3ODEsImlhdCI6MTQ3MDc2MDc5M30.1b4RC22Kpx4X4GWXU-Wgsk4IbeRGVD7tNW-tM-LzkVE';

  expect(validJWT).to.be.have.property('scope'); // Doesn't fail
  expect(validJWT).to.be.have.property('other'); // fails
```

---
_Source: https://npm.io/package/chai-jwt · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
