Make it DRY ;TLDR
During the setup phase of our tests (see Four Phase Test) we typically follow the same setup actions: create a port, create an itinerary and create a ship. This isn't very DRY (Don't Repeat Yourself!). Fortunately, Jest has a beforeEach method that allows us to group similar set up actions in describe blocks.
Challenge
Use Jest's beforeEach method to DRY up the test suite for Ship.
To complete this challenge, you will need to:
- Identify the test specs in
Ship.test.jsthat share the same setup actions. - Create a new
describenested inside of the currentdescribeShipcallback function, and move those test specs inside of it. - In your nested
describe's callback function cut the set up actions from the test specs and add them to abeforeEach. - Run your tests and ensure they still pass.
- Do the same DRYing up inside your
Porttest suite. - Add, commit with a meaningful message, and push to GitHub.
Recommended Reading
- Four Phase Test
- Jest: Setup and Teardown - Would strongly recommend reading. Sections such as
ScopingandOrder of execution of describe and test blocksare very important.