@japa/assert
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

@japa/assert

Assertion library built on top of Chai.assert

github-actions-image npm-image license-image typescript-image

An assertion library built on top of Chai.assert with small tweaks and additional features like assertion planning.

Installation

Install the package from the npm registry as follows:

npm i @japa/assert

yarn add @japa/assert

Usage

You can use the assertion package with the @japa/runner as follows.

import { assert } from '@japa/assert'
import { configure } from '@japa/runner'

configure({
  plugins: [assert()]
})

Once done, you will be able to access the assert property on the test context.

test('test title', ({ assert }) => {
  assert.deepEqual({ id: 1 }, { id: 1})
})

Register open API schemas

You can register open API schema and then assert HTTP responses against.

configure({
  plugins: [assert({
    openApi: {
      schemas: [new URL('../api-spec.json', import.meta.url)]
    }
  })]
})

Validate response as follows.

test('get users', ({ assert }) => {
  const response = await supertest(baseUrl).get('/users')
  assert.isValidApiResponse(response)
})

/@japa/assert/

    Package Sidebar

    Install

    npm i @japa/assert

    Weekly Downloads

    18,969

    Version

    3.0.0

    License

    MIT

    Unpacked Size

    183 kB

    Total Files

    11

    Last publish

    Collaborators

    • virk
    • romainlanz
    • julien-r44