Package Exports
- expect-more-jest
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 (expect-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
expect-more-jest
Write Beautiful Specs with Custom Matchers for Jest
What
A huge library of test matchers a range of common use-cases.
Why
Custom Matchers make tests easier to read and produce relevant and useful messages when they fail.
How
By avoiding vague messages such as "expected false to be true" in favour of useful cues such as "expected 3 to be
even number" and avoiding implementation noise such as expect(paws.length % 2 === 0).toEqual(true)
in favour of
simply stating that you expect(paws.length).toBeEvenNumber()
.
Status
expect-more-jest is a recent TypeScript rewrite of jasmine-expect
.
Most effort is required on documentation and any contributions in this area would be really welcome.
Installation
npm install expect-more-jest --save-dev
Setup
The simplest way to integrate is to include the following in your jest.config.js:
module.exports = {
// ...
setupTestFrameworkScriptFile: require.resolve('expect-more-jest')
// ...
};
If your project requires more setup than just these matchers, point your
setupTestFrameworkScriptFile
entry to a JavaScript file somewhere in your project
like so:
module.exports = {
// ...
setupTestFrameworkScriptFile: '<rootDir>/test/setup-test-framework-script-file.js'
// ...
};
In that file (in this example we have chosen ./test/setup-test-framework-script-file.js
) include:
import 'expect-more-jest';
// ...then your other setup code
or:
require('expect-more-jest');
// ...then your other setup code
API
Asymmetric Matchers
expect.after(date: Date)
expect.arrayOfBooleans()
expect.arrayOfNumbers()
expect.arrayOfObjects()
expect.arrayOfSize(size: number)
expect.arrayOfStrings()
expect.before(date: Date)
expect.calculable()
expect.divisibleBy(other: number)
expect.endingWith(other: string)
expect.evenNumber()
expect.iso8601()
expect.jsonString()
expect.longerThan(other: string | any[])
expect.near(other: number, epsilon: number)
expect.nonEmptyArray()
expect.nonEmptyObject()
expect.nonEmptyString()
expect.oddNumber()
expect.sameLengthAs(other: string | any[])
expect.shorterThan(other: string | any[])
expect.startingWith(other: string)
expect.validDate()
expect.whitespace()
expect.wholeNumber()
expect.withinRange(floor: number, ceiling: number)
Matchers
expect(date: Date).toBeAfter(other: Date)
expect(value).toBeArray()
expect(value).toBeArrayOfBooleans()
expect(value).toBeArrayOfNumbers()
expect(value).toBeArrayOfObjects()
expect(value).toBeArrayOfSize(size: number)
expect(value).toBeArrayOfStrings()
expect(date: Date).toBeBefore(other: Date)
expect(value).toBeBoolean()
expect(value).toBeCalculable()
expect(value).toBeDate()
expect(value).toBeDivisibleBy(other: number)
expect(value).toBeEmptyArray()
expect(value).toBeEmptyObject()
expect(value).toBeEmptyString()
expect(value).toBeEvenNumber()
expect(value).toBeFalse()
expect(value).toBeFunction()
expect(value).toBeIso8601()
expect(value).toBeJsonString()
expect(value: string | any[]).toBeLongerThan(other: string | any[])
expect(value).toBeNonEmptyArray()
expect(value).toBeNonEmptyObject()
expect(value).toBeNonEmptyString()
expect(value).toBeNumber()
expect(value).toBeObject()
expect(value).toBeOddNumber()
expect(value).toBeRegExp()
expect(value: string | any[]).toBeSameLengthAs(other: string | any[])
expect(value: string | any[]).toBeShorterThan(other: string | any[])
expect(value).toBeString()
expect(value).toBeTrue()
expect(value).toBeValidDate()
expect(value).toBeWhitespace()
expect(value).toBeWholeNumber()
expect(value).toBeWithinRange()
expect(value: string).toEndWith(other: string)
expect(value: string).toStartWith(other: string)
expect(fn).toHandleMissingBranches(shape: object | any[])
expect(fn).toHandleMissingLeaves(shape: object | any[])
expect(fn).toHandleMissingNodes(shape: object | any[])
expect(fn).toHandleNullBranches(shape: object | any[])
expect(fn).toHandleNullLeaves(shape: object | any[])
expect(fn).toHandleNullNodes(shape: object | any[])