Cypress · Browser testing end to end

How does test isolation work in Cypress?

Mediumtest isolationstatecleanupUpdated Oct 2026
Quiz this track

Short answer

Test isolation is on by default. Before each test Cypress clears cookies, local storage, session storage and the page state, so tests cannot depend on the previous test's leftovers.

Test isolation makes each test start from a known state. With the default enabled, Cypress clears the browser context between tests: cookies, localStorage, sessionStorage, the page and the application under test. A test that relied on the previous test visiting a page will fail, which is intentional.

ts
describe("isolation", () => {
  it("stores a draft", () => {
    cy.visit("/editor");
    cy.window().then((win) => {
      win.localStorage.setItem("draft", "hello");
    });
  });

  it("starts without the draft", () => {
    cy.visit("/editor");
    cy.window().then((win) => {
      expect(win.localStorage.getItem("draft")).to.be.null;
    });
  });
});
The second test does not see the first test's local storage because isolation reset it.

What isolation changes

  • Cookies, localStorage and sessionStorage are cleared between tests
  • The page is reset, so a test must visit its own starting URL
  • The application is not restarted, so server state can still persist
  • cy.session is the supported way to reuse authentication without fighting isolation
  • testIsolation can be disabled, but doing so makes tests order-dependent

Isolation covers browser state, not backend state. If a test creates a record, that record remains unless the test or a hook removes it. Use a unique identifier per test, seed through an API, or reset the database with cy.task. Do not assume isolation gives you a clean backend.

If a suite only passes when run in a certain order, that is a test isolation bug, not a reason to turn isolation off. Fix the shared state instead.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1What does test isolation clear between tests?
  2. 2Does isolation reset the backend database?
  3. 3How do you preserve authentication across isolated tests?
  4. 4Why is order-dependent testing dangerous?

Say it in the interview

Cypress isolates tests by clearing cookies, local and session storage and the page before each test. That means every test must set up its own starting state. It does not reset the backend, so records created by a test can persist unless I clean them up or use unique data. When a suite depends on order, I treat that as a bug and fix the shared state rather than disabling isolation.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Cypress mock interview and get scored feedback on depth, clarity and confidence.