{
  "doc": {
    "id": "app/core-concepts/test-isolation",
    "title": "Test Isolation",
    "description": "Learn how Cypress ensures test isolation and how to configure test isolation in end-to-end and component testing.",
    "section": "app",
    "source_path": "/llm/markdown/app/core-concepts/test-isolation.md",
    "version": "24a73f8a97175663aaffd3b016289fb2a523a4ea",
    "updated_at": "2026-05-14T20:17:33.301Z",
    "headings": [
      {
        "id": "app/core-concepts/test-isolation#test-isolation",
        "text": "Test Isolation",
        "level": 1
      },
      {
        "id": "app/core-concepts/test-isolation#what-youll-learn",
        "text": "What you'll learn",
        "level": 5
      },
      {
        "id": "app/core-concepts/test-isolation#test-isolation-in-end-to-end-testing",
        "text": "Test Isolation in End-to-End Testing",
        "level": 2
      },
      {
        "id": "app/core-concepts/test-isolation#test-isolation-enabled",
        "text": "Test Isolation Enabled",
        "level": 3
      },
      {
        "id": "app/core-concepts/test-isolation#test-isolation-disabled",
        "text": "Test Isolation Disabled",
        "level": 3
      },
      {
        "id": "app/core-concepts/test-isolation#quick-comparison",
        "text": "Quick Comparison",
        "level": 3
      },
      {
        "id": "app/core-concepts/test-isolation#test-isolation-in-component-testing",
        "text": "Test Isolation in Component Testing",
        "level": 2
      },
      {
        "id": "app/core-concepts/test-isolation#test-isolation-trade-offs",
        "text": "Test Isolation Trade-offs",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "app/core-concepts/test-isolation#what-youll-learn",
      "doc_id": "app/core-concepts/test-isolation",
      "heading": "What you'll learn",
      "heading_level": 5,
      "content_markdown": "##### What you'll learn\n\n*   How Cypress ensures test isolation\n*   How to configure test isolation in end-to-end and component testing\n*   The trade-offs of enabling or disabling test isolation\n\n**Best Practice:** Tests should always be able to be run independently from one another **and still pass**.\n\nAs stated in our mission, we hold ourselves accountable to champion a testing process that actually works, and have built Cypress to guide developers towards writing independent tests from the start.\n\nWe do this by cleaning up state _before_ each test to ensure that the operation of one test does not affect another test later on. The goal for each test should be to **reliably pass** whether run in isolation or consecutively with other tests. Having tests that depend on the state of an earlier test can potentially cause nondeterministic test failures which make debugging challenging.\n\nCypress will start each test with a clean test slate by restoring and clearing all:\n\n*   [aliases](/llm/markdown/api/commands/as.md)\n*   [clock mocks](/llm/markdown/api/commands/clock.md)\n*   [intercepts](/llm/markdown/api/commands/intercept.md)\n*   [spies](/llm/markdown/api/commands/spy.md)\n*   [stubs](/llm/markdown/api/commands/stub.md)\n*   [viewport changes](/llm/markdown/api/commands/viewport.md)\n\nIn addition to a clean test slate, Cypress also believes in running tests in a clean browser context such that the application or component under test behaves consistently when run. This behavior is described as `testIsolation`.\n\nThe test isolation is a global configuration and can be overridden for end-to-end testing at the `describe` level with the [`testIsolation`](/llm/markdown/app/references/configuration.md#e2e) option.\n",
      "section": "app",
      "anchors": [
        "what-youll-learn"
      ],
      "path": "/llm/json/chunked/app/core-concepts/test-isolation.json",
      "token_estimate": 307
    },
    {
      "id": "app/core-concepts/test-isolation#test-isolation-in-end-to-end-testing",
      "doc_id": "app/core-concepts/test-isolation",
      "heading": "Test Isolation in End-to-End Testing",
      "heading_level": 2,
      "content_markdown": "## Test Isolation in End-to-End Testing\n\nCypress supports enabling or disabling test isolation in end-to-end testing to describe if a suite of tests should run in a clean browser context or not.\n\n### Test Isolation Enabled\n\nWhen test isolation is enabled, Cypress resets the browser context _before_ each test by:\n\n*   clearing the dom state by visiting `about:blank`\n*   clearing [cookies](/llm/markdown/api/cypress-api/cookies.md) in all domains\n*   clearing [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) in all domains\n*   clearing [`sessionStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage) in all domains\n\nBecause the test starts in a fresh browser context, you must re-visit your application and perform the series of interactions needed to build the dom and browser state for each test.\n\nAdditionally, the [`cy.session()`](/llm/markdown/api/commands/session.md) command will inherit this configuration and will clear the page and current browser context when establishing a browser session. This is so tests can reliably pass when run standalone or in a randomized order.\n\n### Test Isolation Disabled\n\nWhen test isolation is disabled, Cypress will not alter the browser context before the test starts. The page does not clear between tests and cookies, local storage and session storage will be available across tests in that suite. Additionally, the [`cy.session()`](/llm/markdown/api/commands/session.md) command will only clear the current browser context when establishing the browser session - the current page is not cleared.\n\n### Quick Comparison\n\n| testIsolation | beforeEach test | cy.session() |\n| --- | --- | --- |\n| `true` | \\- clears page by visiting `about:blank`  \n\\- clears cookies in all domains  \n\\- local storage in all domains  \n\\- session storage in all domains | \\- clears page by visiting `about:blank`  \n\\- clears cookies in all domains  \n\\- local storage in all domains  \n\\- session storage in all domains |\n| `false` | does not alter the current browser context |   \n\\- clears cookies in all domains  \n\\- local storage in all domains  \n\\- session storage in all domains |\n",
      "section": "app",
      "anchors": [
        "test-isolation-in-end-to-end-testing"
      ],
      "path": "/llm/json/chunked/app/core-concepts/test-isolation.json",
      "token_estimate": 413
    },
    {
      "id": "app/core-concepts/test-isolation#test-isolation-enabled",
      "doc_id": "app/core-concepts/test-isolation",
      "heading": "Test Isolation Enabled",
      "heading_level": 3,
      "content_markdown": "### Test Isolation Enabled\n\nWhen test isolation is enabled, Cypress resets the browser context _before_ each test by:\n\n*   clearing the dom state by visiting `about:blank`\n*   clearing [cookies](/llm/markdown/api/cypress-api/cookies.md) in all domains\n*   clearing [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) in all domains\n*   clearing [`sessionStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage) in all domains\n\nBecause the test starts in a fresh browser context, you must re-visit your application and perform the series of interactions needed to build the dom and browser state for each test.\n\nAdditionally, the [`cy.session()`](/llm/markdown/api/commands/session.md) command will inherit this configuration and will clear the page and current browser context when establishing a browser session. This is so tests can reliably pass when run standalone or in a randomized order.\n",
      "section": "app",
      "anchors": [
        "test-isolation-enabled"
      ],
      "path": "/llm/json/chunked/app/core-concepts/test-isolation.json",
      "token_estimate": 149
    },
    {
      "id": "app/core-concepts/test-isolation#test-isolation-disabled",
      "doc_id": "app/core-concepts/test-isolation",
      "heading": "Test Isolation Disabled",
      "heading_level": 3,
      "content_markdown": "### Test Isolation Disabled\n\nWhen test isolation is disabled, Cypress will not alter the browser context before the test starts. The page does not clear between tests and cookies, local storage and session storage will be available across tests in that suite. Additionally, the [`cy.session()`](/llm/markdown/api/commands/session.md) command will only clear the current browser context when establishing the browser session - the current page is not cleared.\n",
      "section": "app",
      "anchors": [
        "test-isolation-disabled"
      ],
      "path": "/llm/json/chunked/app/core-concepts/test-isolation.json",
      "token_estimate": 87
    },
    {
      "id": "app/core-concepts/test-isolation#quick-comparison",
      "doc_id": "app/core-concepts/test-isolation",
      "heading": "Quick Comparison",
      "heading_level": 3,
      "content_markdown": "### Quick Comparison\n\n| testIsolation | beforeEach test | cy.session() |\n| --- | --- | --- |\n| `true` | \\- clears page by visiting `about:blank`  \n\\- clears cookies in all domains  \n\\- local storage in all domains  \n\\- session storage in all domains | \\- clears page by visiting `about:blank`  \n\\- clears cookies in all domains  \n\\- local storage in all domains  \n\\- session storage in all domains |\n| `false` | does not alter the current browser context |   \n\\- clears cookies in all domains  \n\\- local storage in all domains  \n\\- session storage in all domains |\n",
      "section": "app",
      "anchors": [
        "quick-comparison"
      ],
      "path": "/llm/json/chunked/app/core-concepts/test-isolation.json",
      "token_estimate": 135
    },
    {
      "id": "app/core-concepts/test-isolation#test-isolation-in-component-testing",
      "doc_id": "app/core-concepts/test-isolation",
      "heading": "Test Isolation in Component Testing",
      "heading_level": 2,
      "content_markdown": "## Test Isolation in Component Testing\n\nCypress does not support configuring the test isolation behavior in component testing.\n\nWhen running component tests, Cypress always resets the browser context _before_ each test by:\n\n*   unmounting the rendered component under test\n*   clearing [cookies](/llm/markdown/api/cypress-api/cookies.md) in all domains\n*   clearing [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) in all domains\n*   clearing [`sessionStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage) in all domains\n",
      "section": "app",
      "anchors": [
        "test-isolation-in-component-testing"
      ],
      "path": "/llm/json/chunked/app/core-concepts/test-isolation.json",
      "token_estimate": 76
    },
    {
      "id": "app/core-concepts/test-isolation#test-isolation-trade-offs",
      "doc_id": "app/core-concepts/test-isolation",
      "heading": "Test Isolation Trade-offs",
      "heading_level": 2,
      "content_markdown": "## Test Isolation Trade-offs\n\nIt is important to note that disabling test isolation may improve the overall performance of end-to-end tests, however, it can also cause state to \"leak\" between tests. This can make later tests dependent on the results of earlier tests, and potentially cause misleading test failures. It is important to be extremely mindful of how tests are written when using this mode, and ensure that tests continue to run independently of one another.\n\nThe best way to ensure your tests are independent is to add a `.only()` to your test and verify it can run successfully without the test before it.\n",
      "section": "app",
      "anchors": [
        "test-isolation-trade-offs"
      ],
      "path": "/llm/json/chunked/app/core-concepts/test-isolation.json",
      "token_estimate": 139
    }
  ]
}