Show Menu
Cheatography

Jest Testing Cheat Sheet (DRAFT) by

Jest API Cheatsheet

This is a draft cheat sheet. It is a work in progress and is not finished yet.

OH

jk
kk
 

Assertions

Basic Equality
.toBe­(va­lue)
===
.toEq­ual­(va­lue)
Asserts equal using deep equal comparison
Spies
.toHa­veB­een­Cal­led()
Asserts mock function was called
.toHa­veB­een­Cal­led­Tim­es(n)
Asserts mock function was called n times
.toHa­veB­een­Cal­led­Wit­h(arg1, arg2, ...)
Asserts mock function was called with provided arguments
.toHa­veB­een­Las­tCa­lle­dWi­th(­arg1, arg2, ...)
Asserts mock function was called with provided arguments on last invocation
Bool­ean­ish
.toBe­Tru­thy()
Asserts value is true in a boolean context
.toBe­Fal­sy()
Asserts value is false in a boolean context
Numeric Compar­isons
.toBe­Gre­ate­rTh­an(­num­ber)
>
.toBe­Gre­ate­rTh­anO­rEq­ual­(nu­mber)
>==
.toBe­Les­sTh­an(­num­ber)
<
.toBe­Les­sTh­anO­rEq­ual­(nu­mber)
<==
.toBeC­los­eTo­(nu­mber, numDig­its)
Asserts number is close to another at given precision
Type Assert­ions
.toBe­Ins­tan­ceO­f(C­lass)
Cont­ain­ment
.toCo­nta­in(­item)
Asserts an array contains item using ===
.toCo­nta­inE­qua­l(i­tem)
Asserts an array contains item using deep equal comparison
.toMa­tch­Obj­ect­(ob­ject)
.toMa­tch­(re­gex­pOr­Str­ing)
Errors
.toTh­row­(er­ror)
Snapshot Testing
.toMa­tch­Sna­psh­ot(­opt­ion­alS­tring)
.toTh­row­Err­orM­atc­hin­gSn­aps­hot()
       

Help Us Go Positive!

We offset our carbon usage with Ecologi. Click the link below to help us!

We offset our carbon footprint via Ecologi