JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 45029
  • Score
    100M100P100Q173373F
  • License MIT

fail cypress test on console error

Package Exports

  • cypress-fail-on-console-error
  • cypress-fail-on-console-error/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cypress-fail-on-console-error) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

cypress-fail-on-console-error

This Plugin observes console.error() function from window object. Cypress test will fail when the error function gets executed.

Installation

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

Usage

cypress/support/index.js

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

failOnConsoleError();

Config (optional)

Parameter Default Description
excludeMessages undefined Exclude console messages from throwing AssertionError
When console.error() contains an error object from new Error(), then the whole stacktrace can be matched
Regular expression parameters are acceptable. String parameters will be interpreted as regular expression. Be sure to escape the string regular expression for special characters.
includeConsoleTypes [consoleType.ERROR] Include console types for observation
cypressLog false Include debug logs for errorMessage_excludeMessage_match and errorMessage_excluded to cypress runner

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

const config = {
    excludeMessages: ['foo', /^some bar-regex.*/],
    includeConsoleTypes: [
        consoleType.ERROR,
        consoleType.WARN,
        consoleType.INFO,
    ],
    cypressLog: true,
};

failOnConsoleError(config);

// excludeMessages[0] matches example console message 'this is a foo message'
// excludeMessages[1] matches example console message 'some bar-regex message'
// includeConsoleTypes observe console types ERROR, WARN and INFO

Using Javascript, consoleType Enum can be parsed as number values

failOnConsoleError({
    includeConsoleTypes: [0, 1, 2],
});

// 0 = INFO
// 1 = WARN
// 2 = ERROR