Skip to main content

Refactor: Repeating Test Code into Hooks

Premium
2 min read

In this lesson, let's see how to avoid repeating some code in the tests.

Now, we use a Factory to create a user in every test. We will extract this part using Pest hooks.


Pest Hooks

Pest offers four hook methods:

  • beforeEach()
  • afterEach()
  • beforeAll()
  • afterAll()

Each has a name that tells when it is being executed. For example, to create a user before the test is run, we can use...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (36 h 00 min)

You also get:

61 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

No comments yet…