This is a draft cheat sheet. It is a work in progress and is not finished yet.
|
|
Assertions
Basic Equality |
|
Asserts equal using deep equal comparison
|
Spies |
Asserts mock function was called
|
.toHaveBeenCalledTimes(n)
Asserts mock function was called n
times
|
.toHaveBeenCalledWith(arg1, arg2, ...)
Asserts mock function was called with provided arguments
|
.toHaveBeenLastCalledWith(arg1, arg2, ...)
Asserts mock function was called with provided arguments on last invocation
|
Booleanish |
Asserts value is true in a boolean context
|
Asserts value is false in a boolean context
|
Numeric Comparisons |
.toBeGreaterThan(number)
|
.toBeGreaterThanOrEqual(number)
|
.toBeLessThan(number)
|
.toBeLessThanOrEqual(number)
|
.toBeCloseTo(number, numDigits)
Asserts number is close to another at given precision
|
Type Assertions |
.toBeInstanceOf(Class)
|
Containment |
Asserts an array contains item using ===
|
.toContainEqual(item)
Asserts an array contains item using deep equal comparison
|
.toMatchObject(object)
|
.toMatch(regexpOrString)
|
Errors |
|
Snapshot Testing |
.toMatchSnapshot(optionalString)
|
.toThrowErrorMatchingSnapshot()
|
|