echoing-kangaroo-83836
05/04/2023, 1:26 PMuseEffect() and then does a window.open() passing _blank as it's second argument like window.open(url, "_blank") which causes it to open in a new tab. While running inside Cypress I want to change this to _self so I can test the URL was properly navigated to. At the top of the useEffect() I'm setting a variable for this using const openLocation = window.Cypress ? '_self' : '_blank'; and then passing openLocation to the window.open() call.
The problem I'm running into is openLocation is always _blank even though when I'm running cypress I can go to the console and do window.Cypress and see there is a Cypress object defined there. Is this some sort of race condition?echoing-kangaroo-83836
05/04/2023, 2:22 PMcy.window().its('Cypress').should('be.an', 'object')echoing-kangaroo-83836
05/04/2023, 2:39 PMwindow.parent.Cypress. Not quite sure why...echoing-kangaroo-83836
05/04/2023, 2:44 PMconst openLocation = window.parent.Cypress ? '_self' : '_blank';
And this also passes in the spec as a sanity check:
cy.window().its('parent.Cypress').should('be.an', 'object')
And according to the MDN docs here: https://developer.mozilla.org/en-US/docs/Web/API/Window/parent
> The Window.parent property is a reference to the parent of the current window or subframe.
>
> If a window does not have a parent, its parent property is a reference to itself.
Since parent references window if there's no parent, this seems like a safe solution.