npm.io
12.0.0 • Published 6d ago

jest-expect-har

Licence
MIT
Version
12.0.0
Deps
3
Size
13 kB
Vulns
0
Weekly
0
Stars
401

jest-expect-har

A Vitest and Jest custom matcher for asserting valid HAR definitions.

npm Build

ReadMe Open Source

Installation

npm install jest-expect-har --save-dev

Usage

import toBeAValidHAR from 'jest-expect-har';
import { expect, test } from 'vitest';

expect.extend({ toBeAValidHAR });

test('should be a valid HAR', () => {
  expect(har).toBeAValidHAR();
});

test('should not be a valid HAR', () => {
  expect(invalidHar).not.toBeAValidHAR();
});

The usage is nearly identical in Jest:

import toBeAValidHAR from 'jest-expect-har';

expect.extend({ toBeAValidHAR });

test('should be a valid HAR', () => {
  expect(har).toBeAValidHAR();
});

test('should not be a valid HAR', () => {
  expect(invalidHar).not.toBeAValidHAR();
});

If your project uses @jest/globals instead of Jest's injected globals, toBeAValidHAR is typed there too:

import { expect, test } from '@jest/globals';
import toBeAValidHAR from 'jest-expect-har';

expect.extend({ toBeAValidHAR });

test('should be a valid HAR', () => {
  expect(har).toBeAValidHAR();
});

Keywords