Package Exports
- @giancosta86/more-jest
- @giancosta86/more-jest/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@giancosta86/more-jest) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
more-jest
TypeScript matchers and utilities for Jest
more-jest is a TypeScript library providing additional matchers for Jest as well as types and utilities for creating custom matchers; consequently, it serves as the fundamental building block for dedicated libraries like more-jest-io.
Installation
npm install @giancosta86/more-jest
or
yarn add @giancosta86/more-jest
The public API entirely resides in the root package index, so one shouldn't reference specific modules from TypeScript code.
Global matchers
In order to be able to access the custom matchers provided by this library within any test file in your project, please follow these steps:
Create a declaration file (for example,
global.d.ts
) in the root directory of your project, containing the following line:import "@giancosta86/more-jest";
In the
jest.config.js
configuration file, add an entry to thesetupFilesAfterEnv
array field:module.exports = { setupFilesAfterEnv: ["@giancosta86/more-jest/dist/all"] };
Matchers
toBeTrimmed()
: ensures that the received string contains neither leading nor trailing spaces:expect("DODO").toBeTrimmed(); //OK expect(" DODO").toBeTrimmed(); //FAILURE! expect("DODO ").toBeTrimmed(); //FAILURE!
Utilities
more-jest provides:
the
MatcherResult
readonly type - which should be the return type of custom matcher handlersthe
failMatcherIf()
function, designed to be called as the return value of custom matcher handlersthe
matcherSuccess
constant - to be returned by more sophisticated matcher handlers
Further references
- more-jest-io - TypeScript I/O matchers and utilities for Jest