Sharing Authentication State

Learn about sharing authentication states and how to use it to speed up the test.

We know that the state must not be shared between subsequent tests because it’s the first reason for brittle tests .

Remember the Testing Rules: why should we not share the state between tests? Imagine this scenario:

  • test a registers a new user and performs actions that require the user to be registered.
  • test b preforms actions that require the user to be registered

You are going to break test b test if

  • You run it alone with it.only().

  • You skip the test a with it.skip().

  • You change the order.

  • You move the test b to another file or vice-versa.

Every test must be independent.

In the previous lesson, we improved test performance, but it’s still quite slow. To maintain independence, we could write a custom command that registers a new user, stores the user token, and restores ...