From the course: End-to-End JavaScript Testing with Cypress.io
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
The "beforeEach" hook
From the course: End-to-End JavaScript Testing with Cypress.io
The "beforeEach" hook
- [Narrator] So we have seen a few different ways to make our Cypress tests less verbose. But there is still a little repetition going on in our code. In both our tests for example were navigating to the exact same page and to finding the same aliases. Re-phrase. In both our tests for example were navigating to the exact same page and to finding the same aliases. Right here. And right here. Now wouldn't it be nice if we could just do that once for all the tests in one block. Well fortunately Cypress provides a way for us to do this, and that's by using a before each block. So before we look at how to do that. Lets copy and paste our alias.speck file. And then rename it before-each-speck.js. Now those of you who have worked with Mocha or pretty much any other testing framework before are probably familiar with before each blocks. They allow us to right code that will get executed before each of our tests run. And what it…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.