Fireship · @fireship

Cypress in 100 Seconds

Uploaded March 29, 2022 · Length 2:31

Cypress in 100 Seconds

Summary

Cypress is a testing solution for web applications that makes test-driven development fun for JavaScript developers.

  • cypress testing
  • javascript testing
  • web application testing
  • test driven development
  • end to end testing

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    Cyprus a testing solution for web

  2. 0:02

    applications famous for making test

  3. 0:04

    driven development fun for JavaScript

  4. 0:06

    developers we all know testing is the

  5. 0:08

    right thing to do but actually doing it

  6. 0:10

    in a front-end JavaScript project can be

  7. 0:12

    complicated slow and just not fun for

  8. 0:14

    many the obvious solution is to simply

  9. 0:16

    not test anything at all that's not

  10. 0:18

    ideal Cypress provides an open source

  11. 0:20

    browser-based test Runner that can

  12. 0:22

    experience your website just like the

  13. 0:24

    end user would it might fill out a login

  14. 0:25

    form click the submit button then

  15. 0:27

    navigate to the user dashboard all of

  16. 0:29

    which happens programmatically based on

  17. 0:31

    code you define every test is recorded

  18. 0:33

    and a snapshot is saved at each step

  19. 0:35

    this makes it possible to time travel

  20. 0:37

    through the user experience to figure

  21. 0:38

    out precisely why your code sucks and

  22. 0:41

    unlike traditional testing utilities

  23. 0:42

    debugging can be performed directly from

  24. 0:44

    the browser Dev tools not only does it

  25. 0:46

    work for end to-end testing of an entire

  26. 0:48

    application but it's also great for

  27. 0:50

    integration testing and unit testing of

  28. 0:53

    isolated components or JavaScript

  29. 0:54

    business logic to get started install it

  30. 0:57

    into your project then run npx Cypress

  31. 0:59

    own open notice how this pulls up the

  32. 1:01

    test Runner automatically and creates a

  33. 1:03

    folder in the root of your project named

  34. 1:05

    Cyprus that contains all of your testing

  35. 1:07

    code fixtures is where you would Define

  36. 1:08

    mock data plugins allow you to hook into

  37. 1:11

    the testing life cycle support is for

  38. 1:13

    your Global configuration then your main

  39. 1:15

    testing code lives in the integration

  40. 1:17

    file we can create a test Suite with

  41. 1:19

    describe then before each test we can

  42. 1:21

    run some setup code like tell Cypress to

  43. 1:23

    visit a specific URL from there use it

  44. 1:26

    to describe a test case where you might

  45. 1:28

    verify that the web page contains a a

  46. 1:30

    certain piece of content the git method

  47. 1:31

    will grab an element from the Dom and

  48. 1:33

    allow you to run assertions on it like

  49. 1:35

    it should have the text login it bundles

  50. 1:37

    the chai assertion library for

  51. 1:39

    behavior-driven development which will

  52. 1:41

    autocomplete with intellisense from

  53. 1:42

    there you may want to find a form input

  54. 1:45

    and type something into it after the

  55. 1:46

    form is filled out submit it to update

  56. 1:48

    your database the great thing about

  57. 1:50

    Cypress is that it will automatically

  58. 1:51

    wait for async events which means you

  59. 1:53

    don't need to add a bunch of sleepers in

  60. 1:55

    your test code things just work

  61. 1:56

    naturally now run your test to watch

  62. 1:58

    everything go down visually a snapshot