$30 off During Our Annual Pro Sale. View Details »

Take a snapshot - ngvikings

Take a snapshot - ngvikings

Bo Vandersteene

May 28, 2019
Tweet

More Decks by Bo Vandersteene

Other Decks in Programming

Transcript

  1. Take a snapshot Bo Vandersteene @reibo_bo

  2. @reibo_bo @reibo_bo @bo.vandersteene Software Engineer & Coach

  3. Snapshot

  4. None
  5. Snapshot a component

  6. None
  7. None
  8. None
  9. Snapshot a block of code

  10. None
  11. None
  12. Test case Render UI component Test against snapshot

  13. How we do it with Jasmine

  14. None
  15. • A lot of lines • Forget code to test

    • Hard to define all cases • Nice feedback • ...
  16. Should we skip

  17. E2E <> Unit

  18. Unit test - Small easily - Function - Class -

    Complex algorithm
  19. E2E test - Take screenshots - Entire application - Flows

    - Cypress, protractor, ...
  20. Unit tests !

  21. Testing is HARD

  22. None
  23. Why Jest Fast Sandboxed Zero Config Snapshots Error reporting

  24. Zero config

  25. http://bit.ly/2M28O9W

  26. http://bit.ly/2M28O9W

  27. http://bit.ly/2M28O9W

  28. http://bit.ly/2M28O9W Each app/lib tsconfig.spec.json

  29. http://bit.ly/2M28O9W

  30. http://bit.ly/2M28O9W Each app/lib angular.json

  31. http://bit.ly/2M28O9W

  32. http://bit.ly/2M28O9W

  33. http://bit.ly/2M28O9W

  34. Snapshot testing

  35. None
  36. None
  37. None
  38. None
  39. • Creates the snapshot if it doesn’t exist

  40. • Creates the snapshot if it doesn’t exist

  41. • Creates the snapshot if it doesn’t exist

  42. None
  43. None
  44. • Creates the snapshot if it doesn’t exist • Compares

    expectation to stored snapshot • Performs a diff
  45. • Creates the snapshot if it doesn’t exist • Compares

    expected to stored snapshot • Performs a diff • Easily update snapshot on refactor
  46. • Creates the snapshot if it doesn’t exist • Compares

    expected to stored snapshot • Performs a diff • Easily update snapshot on refactor
  47. Commit snapshot

  48. Not only components!

  49. None
  50. None
  51. None
  52. RxJs

  53. None
  54. None
  55. None
  56. None
  57. Globals

  58. Globals afterAll afterEach beforeAll beforeEach describe.each describe.only describe.only.each describe.skip describe.skip.each

    test.each test.only test.only.each test.skip test.skip.each test.todo describe test
  59. None
  60. None
  61. None
  62. None
  63. Mock

  64. None
  65. None
  66. None
  67. None
  68. None
  69. None
  70. None
  71. None
  72. None
  73. Tips & Tricks

  74. Make your tests your documentation

  75. Test logic

  76. Use beforEach Use afterEach

  77. Treat snapshots as code

  78. Tests should be deterministic

  79. Units NOT methods

  80. ng test -u

  81. Commit snapshots

  82. ci-tools ng test

  83. Love testing

  84. Thank You @reibo_bo @bo.vandersteene https://github.com/reibo/jest-example