brash-plumber-67474
02/01/2023, 12:26 PMshould open app in new tab, () => {
cy.mount();
cy.spy(window, 'open').as('windowOpen');
const uniqueAppName = 'Sample App';
const expectedURL = 'http://localhost/sampleapp';
cy.contains(uniqueAppName).should('be.visible').click();
cy.get('@windowOpen').should('have.been.calledWith', expectedURL, '_blank');
});
});
But the problem is the URL that opens up in new tab return 404 error and I know that it will return 404 because it is a dummy URL. I don't care whatever that new tab returns I just wanted to test if that URL was called by window.open function. While running the test in Cypress desktop app (using cypress open command)
the test shows it passed and runs all the other tests as well.
But when running the test using cypress run command (in headless mode), the CLI passes the current test then throws error 404 and exits out and does not run rest of the tests. Is there a way to just ignore that error because I am anyway expecting it?
I have attached the error message.
If you think this is an incorrect approach to test a link in new tab, please do suggest what should be the right approach?
Another query:
If I am expecting an error that is known, like in above scenario I knew I will be getting a 404 error, is it a good practice to do error handling in a test environment like using try-catch blocks?gray-kilobyte-89541
02/01/2023, 12:45 PMechoing-tent-95037
02/01/2023, 9:50 PMcy.stub(win, 'open') and then later after you click the button to open the tab cy.get('@open).should('have.been.calledOnce')thousands-house-85089
02/02/2023, 2:59 AMthousands-house-85089
02/02/2023, 2:59 AM