@knowdev/jest

1.1.0 • Public • Published

KnowDev Jest Extensions 🃏

📋 Usage

npm install --save @knowdev/jest

jest.config.js

module.exports = {
  setupFilesAfterEnv: ["jest-extended", "@knowdev/jest"],
};

📖 Reference

toBeAsyncIterator()

Checks that a special symbol, subject[Symbol.asyncIterator], exists and is a function. Does not exercise iterator

expect(subject).toBeAsyncIterator();

toBeClass()

Attempts to instantiate subject

expect(subject).toBeClass();

toBeCalledWithInitialParams()

Unlike toHaveBeenCalledWith(), which matches the entire set of parameters, toBeCalledWithInitialParams() only matches the first n parameters. E.g., if you want to test only the first parameter

# Passes:
mockFunction(1, 2, 3);
expect(mockFunction).toBeCalledWithInitialParams(1, 2);

# Fails:
mockFunction(1);
expect(mockFunction).toBeCalledWithInitialParams(1, 2);

toBeProjectError()

Checks that the subject is a ProjectError instance

expect(error).toBeProjectError();

toThrowProjectError(), toThrowProjectErrorAsync()

Checks that the thrown error is an instance of ProjectError. Can be called with any of the following matchers, which much all match:

  • String (matches as a substring)
  • RegExp
  • ProjectError class

Strings and RegExps are matched against the error title or detail fields. ProjectError classes compare the title and status fields but not detail.

expect(() => functionCall(...params)).toThrowProjectError();

expect(() => functionCall(...params)).toThrowProjectError(InternalError, "Internal Application", /internal application/i);

🚀 Deployment

npm run publish

📝 Changelog

  • 1.1.0: adds toBeProjectError()
  • 1.0.2: Split toThrowProjectError() into sync and totoThrowProjectErrorAsync() versions
  • 1.0.1: toThrowProjectError() supports async functions
  • 1.0.0: arbitrary starting point
  • 0.4.0: adds toThrowProjectError() (unpublished)
  • 0.3.0: adds toBeAsyncIterator()
  • 0.2.0: adds toBeCalledWithInitialParams()
  • 0.1.0: adds toBeClass()

🛣 Roadmap

N/A

Wishlist 🌠

  • toMatchJsonApiErrorSchema()

📜 License

All rights reserved. Safe for use around pets.

Readme

Keywords

none

Package Sidebar

Install

npm i @knowdev/jest

Weekly Downloads

0

Version

1.1.0

License

UNLICENSED

Unpacked Size

24.2 kB

Total Files

9

Last publish

Collaborators

  • nullfame