Unit Tests
in proton-mail
Theory
Jest
- Done by Facebook engineering
- It's the best modern test runner
- It includes mocking and assetions features
- Runs tests inside JSDom a Node based browser emulator
- Not linked to React so don't includes features for testing React components
- Beware, Jest skip the Webpack packaging!
Enzyme
- Started at AirBNB
- https://enzymejs.github.io/enzyme/
- Lack of support
- https://github.com/enzymejs/enzyme/issues/1553
Testing Library
- Most recomended library today
- https://testing-library.com/docs/react-testing-library/intro
- Started on React, today multi-framework
- Created and mostly maintained by Kent C. Dodds
Testing phylosophies
- Isolation
- From third parties services
- From third parties libraries
- From the inside of the project
- Mocking
- All the things
- In last resort
- Shallow rendering
- Not rendering the inner components
- Good or bad?
Testing Library
=
no mocking
My only doubt
Is it still unit tests or integration tests?
React Hooks Testing Library
- Plugin dedicated to test hooks outside of a component
- https://react-hooks-testing-library.com/
- Not really easy to use
On proton-mail
Custom render
Minimal mocking
- https://gitlab.protontech.ch/web/mail/proton-mail/-/blob/develop/jest.setup.js
- https://gitlab.protontech.ch/web/mail/proton-mail/-/tree/develop/src/__mocks__
- Some mock are needed to avoid require.context only supported by Webpack, not Jest
Complete test environment
(Built progressively)
Includes helpers for:
- API
- Cache management
- Event manager
- Recently: cryptography
Some real unit tests
- Labels logic
https://gitlab.protontech.ch/web/mail/proton-mail/-/blob/develop/src/app/helpers/labels.ts - Paging logic
https://gitlab.protontech.ch/web/mail/proton-mail/-/blob/develop/src/app/helpers/paging.test.ts - Icons logic
https://gitlab.protontech.ch/web/mail/proton-mail/-/blob/develop/src/app/helpers/message/icon.test.ts
Some, a lot more high level
Thanks
deck
By Matthieu Lux
deck
- 234