https://cypress.io logo
So I am currently doing something like this instea...
# e2e-testing
u
So I am currently doing something like this instead:
Copy code
beforeEach(function () {
    let spySetup = function(window) {
        let config = this.mocha.getRunner().test.ctx.consoleLoggingTestConfig;
        config.spies.ERROR = sinon.spy(window.console, 'error');
        config.spies.WARN = sinon.spy(window.console, 'warn');
    };
    let spyAssertion = function() {
        let config: ConsoleLoggingTestConfig = this.mocha.getRunner().test.ctx.consoleLoggingTestConfig;
        assertSpiedConsoleLogs(config, ConsoleType.ERROR);
        assertSpiedConsoleLogs(config, ConsoleType.WARN);
    };

    Cypress.on('window:before:load', spySetup);
    Cypress.on('command:end', spyAssertion);

    this.test.ctx.consoleLoggingTestConfig = <ConsoleLoggingTestConfig>{
        consoleTypes: [ConsoleType.ERROR],
        excludedMessages: {
            ERROR: [
                'while rendering',
                'blabla'
            ],
            WARN: []
        },
        spies: {},
        spySetupFunc: spySetup,
        spyAssertionFunc: spyAssertion
    };
});

afterEach(function () {
    const config: ConsoleLoggingTestConfig = this.test.ctx.consoleLoggingTestConfig;
    Cypress.removeListener('window:before:load', config.spySetupFunc);
    Cypress.removeListener('command:end', config.spyAssertionFunc);
});