https://cypress.io logo
Scope of "testIsolation"
# i-need-help
f
Hi all, I have
testIsolation
set to true at a global level. I'd like certain describe blocks to run without
testIsolation
, so that I can run several
it
commands in sequence, each with an assertion. According to the docs, I can define
testIsolation
at a
describe
level. My interpretation is that is would apply to block only, but it doesn't appear to work like that, or perhaps I'm misunderstanding. Here's an example, for a given spec file
Copy code
describe('Some tests', () => {

  describe('Test A', { testIsolation: false }, () => {
    it('C1: verifies something', () => {
      // run some assertion
    });
    
    it('C2: verifies something else', () => {
      // run some assertion
    });
  });
  
  describe('Test B', { testIsolation: false } () => {
    it('C3: verifies something', () => {
      // run some assertion
    });
    
    it('C4: verifies something else', () => {
      // run some assertion
    });
  });
});
In this case, I'd expect
testIsolation
to only be applicable to the "inner"
it
commands. That is, "Test A" and "Test B" would run in isolation of each other. In practice, I'm observing "Test B" doesn't clear the browser session, etc. Thanks!
i
As you are using Nested Describe its looking like a problem for you Try to check once by executing without Outer describe 'Some tests'
f
hah. let me try that
Same behavior. Note: I'm using the Cypress Test Runner, but this also happens in CI As soon as I launch the test spec, the usual message
Default blank page This page was cleared by navigating to about:blank. All active session data (cookies, localStorage and sessionStorage) across all domains are cleared.
doesn't even appear
It's like the presence of that
testIsolation: false
just disables it for the entire spec
oh, someone beat me to reporting an issue 🙂 https://github.com/cypress-io/cypress/issues/26049
i
ok please look into this article. which may help you set some configurations if possible? as even long back I landed into the same problem https://wordpress.com/read/feeds/137922491/posts/4545179635
e
I thought that with Test Isolation enabled, Cypress resets the browser context before each test. Not after. So if its disabled, then its not going to clear up after itself. I thought this goes hand in hand with the principle of setting the state before each test, not relying on an after hook of a previous request that you don't know succeded or not. Same princple applies to test data. Your before should ensure that the state is correct. Not rely on a previous test clearing up after itself. https://docs.cypress.io/guides/core-concepts/test-isolation
f
@incalculable-rainbow-43330 I get a login screen with that link
@enough-summer-50273 I think that's aligned with my expectation: each
describe
(whether nested or not) should "reset/clear" browser context when
testIsolation
is
true
. Only if a
describe
does override
testIsolation: false
it should not
i
f
thank you @incalculable-rainbow-43330 ! I ended up adopting a similar solution... Kind of sucks any way, would hope it would be built-in 🙂
i
yah i think Cypress would have given it by default as false and if we want we can set it to True in that way there use to be no confusion, but it happened in other way 🙂 Good Luck
30 Views