questionar
questionar

Reputation: 284

how to stub window.open in testcafe

I would like to mock the window.open function in testcafe. so that if my app calls window.open rather than hitting actual one we can use mock

something like this would be better

onBeforeLoad: (window) => {
   cy.stub(window, 'open');
}

Upvotes: 1

Views: 621

Answers (1)

AlexanderMoiseev
AlexanderMoiseev

Reputation: 556

To achieve this goal, use the 'Inject Scripts into Tested Pages' feature.

const mockWindowOpen = "window.open = function () { };";
test
   ('My test', async t => { /* ... */ })
   .clientScripts({ content: mockWindowOpen });

Upvotes: 7

Related Questions