PAVITHRA KODMAD | DEVELOPER
Introduction to Jest
Jest is
Javascript
Testing
Framework/
Platform
INTRODUCTION
Why Jest?
Why Jest?
Sandboxed
Tests
Feedback loop
One stop shop
Community
Sandboxed Tests
• Tests run in parallel
• No shared state between tests
Why Jest?
Sandboxed
Tests
Feedback loop
One stop shop
Community
Better Feedback loop
• Rich CLI
• Pretty logging
• Better error outputs
• Failed tests run first
• Coverage
Why Jest?
Sandboxed
Tests
Feedback loop
One stop shop
Community
One stop shop
Why Jest?
Sandboxed
tests
Feedback loop
One stop shop
Community
Community
Back in 2015 👇
Why Jest?
Sandboxed
tests
Feedback loop
One stop shop
Community
Community
Now 👇
Why Jest?
Sandboxed
tests
Feedback loop
One stop shop
Community
Community
Why Jest?
Sandboxed
tests
Feedback loop
One stop shop
Community
Community
• Atlaskit actively using and developing
tools on Jest
• Jest codemods
Anatomy of a test
What’s different?
• Globals - describe/expect/test
What’s different?
• Matchers
What’s different?
What’s different?
How to mock?
How to mock?
Mock Hoisting
Hoists mocks to top of file by default
Prevent with doMock
Spy behavior
jest.spyOn always called the spied function.
Tip : toBe() vs toEqual()
Tip : jest.resetModules
Call to clear any pending state in module cache between tests
Tip : mockImplementationOnce()
Tip : expect.anything()
Tip : expect.extend()
Tip : mockFn.mock.instances
Useful to get the source mockImplementation
Tip : jest.isMockFunction()
Useful to check!
Tip : coverage and coverage thresholds
Tip : Snapshot Testing
Can take snapshots of
• Components
• Json
• String
• Anything serializable
Tip : —runInBand
Jest always run in parallel
• Makes it run on a single thread
• Easier to debug
Tip : Vscode and Jest
Tip :Async testing
Very similar to what we had with Mocha and Chai
Cheers to “Painless” testing
References
• Jest Documentation - https://github.com/kalcifer/awesome-jest
• Jest as a Platform - https://github.com/rogeliog/jest-as-a-platform-talk/blob/maste
Jest%20as%20a%20Platform.pdf
• Jest historically - http://rea.tech/painless-javascript-testing-surely-you-jest/
• Jest codemods - https://github.com/skovhus/jest-codemods
• Chai and Jest Matchers - https://medium.com/@RubenOostinga/combining-chai-
matchers-d12d1ffd0303
• VsCode Jest - https://github.com/orta/vscode-jest
• Jest codemods and Sinon - https://github.com/skovhus/jest-codemods/issues/68
• Manjula Dube for this slide - https://twitter.com/manjula_dube/status/9402921548
Thank you

Introduction to jest