Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Introduction to jest

163 views

Published on

Assuming the audience already knows how to test in Javascript

Published in: Software
  • Be the first to comment

  • Be the first to like this

Introduction to jest

  1. 1. PAVITHRA KODMAD | DEVELOPER Introduction to Jest
  2. 2. Jest is Javascript Testing Framework/ Platform INTRODUCTION
  3. 3. Why Jest?
  4. 4. Why Jest? Sandboxed Tests Feedback loop One stop shop Community Sandboxed Tests • Tests run in parallel • No shared state between tests
  5. 5. 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
  6. 6. Why Jest? Sandboxed Tests Feedback loop One stop shop Community One stop shop
  7. 7. Why Jest? Sandboxed tests Feedback loop One stop shop Community Community Back in 2015 👇
  8. 8. Why Jest? Sandboxed tests Feedback loop One stop shop Community Community Now 👇
  9. 9. Why Jest? Sandboxed tests Feedback loop One stop shop Community Community
  10. 10. Why Jest? Sandboxed tests Feedback loop One stop shop Community Community • Atlaskit actively using and developing tools on Jest • Jest codemods
  11. 11. Anatomy of a test
  12. 12. What’s different? • Globals - describe/expect/test
  13. 13. What’s different? • Matchers
  14. 14. What’s different?
  15. 15. What’s different?
  16. 16. How to mock?
  17. 17. How to mock?
  18. 18. Mock Hoisting Hoists mocks to top of file by default Prevent with doMock
  19. 19. Spy behavior jest.spyOn always called the spied function.
  20. 20. Tip : toBe() vs toEqual()
  21. 21. Tip : jest.resetModules Call to clear any pending state in module cache between tests
  22. 22. Tip : mockImplementationOnce()
  23. 23. Tip : expect.anything()
  24. 24. Tip : expect.extend()
  25. 25. Tip : mockFn.mock.instances Useful to get the source mockImplementation
  26. 26. Tip : jest.isMockFunction() Useful to check!
  27. 27. Tip : coverage and coverage thresholds
  28. 28. Tip : Snapshot Testing Can take snapshots of • Components • Json • String • Anything serializable
  29. 29. Tip : —runInBand Jest always run in parallel • Makes it run on a single thread • Easier to debug
  30. 30. Tip : Vscode and Jest
  31. 31. Tip :Async testing Very similar to what we had with Mocha and Chai
  32. 32. Cheers to “Painless” testing
  33. 33. 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
  34. 34. Thank you

×