Mee-KeH-LeH
Front End Engineer at Facebook
Author of React Design Patterns and Best Practices
Follow me @MicheleBertoli
Slide 3
Slide 3 text
“I'm upgrading a pretty big
codebase from Jest 0.8.2 to 15.1.1.
Call me a hero.”
— Michele Bertoli, Sep 2016
Slide 4
Slide 4 text
Testing
Slide 5
Slide 5 text
“Saddest thing I hear from
engineers: we aren't writing tests
right now because we're focusing
on building features”
— Dmitrii Abramov, Feb 2017
Slide 6
Slide 6 text
● Time consuming
● Complex to setup and maintain
● Browser tests are slow
● False negatives
Testing is hard
Slide 7
Slide 7 text
● Catch some bugs
● Confidence (Move fast™)
● Refactoring
● Documentation
Testing is important
Slide 8
Slide 8 text
“Unpopular opinion: component
unit testing is overrated.”
— Dan Abramov, Jul 2016
Slide 9
Slide 9 text
“Write tests. Not too many. Mostly
integration.”
— Guillermo Rauch, Dec 2016
Slide 10
Slide 10 text
Mike Cohn, Nov 2009
Slide 11
Slide 11 text
Dmitrii Abramov, Dec 2016
Slide 12
Slide 12 text
jest
Slide 13
Slide 13 text
● Focus on DX
● Works out of the box
● Complete product
● Used by Facebook
overview
Slide 14
Slide 14 text
● Interactive mode
● Automatically find tests related to changed files
● Run tests in parallel processes
● Sandboxed test files and automatic state resets
FAST
Slide 15
Slide 15 text
● Create coverage reports
● Run your tests within a fake DOM implementation
● Integrated manual mocking library
ALL-IN-ONE
Slide 16
Slide 16 text
● Error messages are helpful and color coded
● Stack traces point to the source of problems
● Jest runs previously failed tests first
ERRORS
Slide 17
Slide 17 text
● Jest works with any compile-to-JS language
● Integrates seamlessly with Babel
● TypeScript through ts-jest
Integrations
Slide 18
Slide 18 text
● Integrated support for promises and async/await
● Can run asynchronous code synchronously
ASYNC
Slide 19
Slide 19 text
Setup
Slide 20
Slide 20 text
npm install --save-dev jest
yarn add --dev jest
// package.json
"scripts": {
"test": "jest"
}
Getting Started
watch
Watch Usage
› Press a to run all tests.
› Press o to only run tests related to changed files.
› Press u to update failing snapshots.
› Press p to filter by a filename regex pattern.
› Press q to quit watch mode.
› Press Enter to trigger a test run.
Slide 47
Slide 47 text
enzyme-to-json
Convert Enzyme wrappers to a format compatible with
Jest snapshot testing.
adriantoine/enzyme-to-json