Jest Snapshot Testing for React Components(An Honest Assessment)

What Are We Testing?

Dynamic Rendered Output

What Does It Not Test?

How Did We Test This?

#1 Plain Enzyme and Jest Matchers

#2 Custom Enzyme Matchers for Jest

The Pain Points

Testing With Jest Snapshot Testing

Let’s Get Visual

Basic Examples

The Advantages

Setting Boundaries

jest.mock('./Title', () => 'Title')

Combining With Enzyme

Handling Dynamic Rendering

Covering Pass-Through Props

Objections to Snapshot Testing

Snapshots Can Be Updated Too Easily

Snapshot Testing Can Have A Lot of Duplication

Snapshots Can Be Hard to Read

Snapshots Can Get Very Long

Final Words

UI Developer in Southwest Virginia. Soli Deo Gloria.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store