This is a draft cheat sheet. It is a work in progress and is not finished yet.
| | AssertionsBasic Equality | .toBe(value)
===
| .toEqual(value)
Asserts equal using deep equal comparison | Spies | .toHaveBeenCalled()
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 | .toBeTruthy()
Asserts value is true in a boolean context | .toBeFalsy()
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 | .toContain(item)
Asserts an array contains item using === | .toContainEqual(item)
Asserts an array contains item using deep equal comparison | .toMatchObject(object)
| .toMatch(regexpOrString)
| Errors | .toThrow(error)
| Snapshot Testing | .toMatchSnapshot(optionalString)
| .toThrowErrorMatchingSnapshot()
|
|
Help Us Go Positive!
We offset our carbon usage with Ecologi. Click the link below to help us!