Reputation: 284
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
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