npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cypress-fail-on-console-error

v6.1.0

Published

fail cypress test on console error

Readme

cypress-fail-on-console-error

npm CI Sponsor

Fail Cypress tests when the application under test calls console.error(). Set up once in your support file, it checks every test for errors that your app or third-party scripts catch and only log, which Cypress doesn't fail on. Works for e2e and component tests.

To fail tests on network errors, see cypress-fail-on-network-error.

Installation

npm install cypress-fail-on-console-error --save-dev

Usage

Call failOnConsoleError() in your support file: cypress/support/e2e.js for e2e tests, cypress/support/component.js for component tests, or the .ts versions of these files.

import failOnConsoleError from 'cypress-fail-on-console-error';

failOnConsoleError();

When the application calls console.error(), the test fails after the current command:

Configuration

| Option | Default | Description | | ----------------------- | ----------- | ----------- | | ignoreConsoleMessages | [] | Console messages that don't fail a test, see Matching messages. | | consoleTypes | ['error'] | Console methods that fail a test: error, warn, info, debug, trace, table, log or assert. | | debug | false | Also logs each message that ignoreConsoleMessages ignores, with the entry that matched it. See Debugging. |

import failOnConsoleError, { type Config } from 'cypress-fail-on-console-error';

const config: Config = {
    ignoreConsoleMessages: [
        'ResizeObserver loop',
        'unique "key" prop',
        { type: 'warn', message: 'is deprecated' }, // only for console.warn
    ],
    consoleTypes: ['error', 'warn'],
};

failOnConsoleError(config);

To fail only on messages that contain some text, ignore every message that doesn't contain it:

failOnConsoleError({
    // ignore every message that doesn't contain React
    ignoreConsoleMessages: [/^(?![\s\S]*React)/],
});

Matching messages

An entry is a string, a RegExp, or { type, message }, which only ignores calls of that console method. A message that matches any entry is ignored.

  • A string or RegExp matches anywhere in the message. Strings are converted with new RegExp(string), so escape special characters.
  • The message is all arguments of the console call, joined with spaces. Objects are converted to JSON: console.error('Failed to load user', { id: 42 }) becomes Failed to load user {"id":42}.
  • An Error becomes its name, message and stack trace, such as TypeError: user is undefined followed by lines like at render (app.js:12:5), so you can also match the file an error came from.

Ignoring messages in one test

To change the ignored messages in a test, register the commands in your support file:

import failOnConsoleError, {
    addIgnoredConsoleMessagesCommands,
} from 'cypress-fail-on-console-error';

const failOnConsole = failOnConsoleError(config);
addIgnoredConsoleMessagesCommands(failOnConsole);

Then use them in a test. Changes last until the end of the test.

it('should show the page without recommendations', () => {
    cy.addIgnoredConsoleMessages(['Failed to load recommendations']);
    cy.visit('/');
});

| Command | Description | | --------------------------------------------------------- | ----------- | | cy.getIgnoredConsoleMessages() | Yields ignoreConsoleMessages. | | cy.setIgnoredConsoleMessages(['ResizeObserver loop']) | Replaces ignoreConsoleMessages. | | cy.addIgnoredConsoleMessages(['is deprecated']) | Adds to ignoreConsoleMessages. | | cy.deleteIgnoredConsoleMessages(['ResizeObserver loop']) | Removes from ignoreConsoleMessages. |

To change consoleTypes or debug in a test, use getConfig() and setConfig(), which failOnConsoleError() returns:

import { type ConsoleType } from 'cypress-fail-on-console-error';

const { getConfig, setConfig } = failOnConsole;

Cypress.Commands.add('setConsoleTypes', (consoleTypes: ConsoleType[]) =>
    setConfig({ ...getConfig(), consoleTypes })
);

declare global {
    namespace Cypress {
        interface Chainable {
            setConsoleTypes(consoleTypes: ConsoleType[]): Chainable<void>;
        }
    }
}

Debugging

Click a console.error entry in the command log to print the original arguments and the message your ignoreConsoleMessages were matched against to the browser console.

Set debug: true to also log each ignored message, with the entry that matched it:

failOnConsoleError({
    ignoreConsoleMessages: ['ResizeObserver loop'],
    debug: true,
});

Contributing

See CONTRIBUTING.md.