jasmine-matcher-errors

1.0.0 • Public • Published

jasmine-matcher-errors

Customize the error message reported by a custom jasmine matcher.

Why?

The message returned by a custom jasmine matcher is duplicated into the error object created for the failed spec. This results in error messages always being output twice.

screenshot from 2016-06-01 09-04-53

Once you can customize the error message you could keep the message brief, and put more detailed information in the error message, or whatever makes sense for your custom matcher.

screenshot from 2016-06-01 09-05-56

Setup

jasmine-node

  1. Install from npm.
  • npm install --save-dev jasmine-matcher-errors
  1. Include in your custom matchers.
  • require('jasmine-matcher-errors')

jasmine

  1. Install from bower.
  • bower install --save-dev jasmine-matcher-errors
  1. Include before your custom matchers.
  • <script type="text/javascript" src="bower_components/jasmine-matcher-errors/src/index.js"></script>

Usage

Simply add an error object to the return object of your custom matcher.

jasmine.addMatchers({
  exampleMatcher: function() {
    return {
      compare: function(actual, expected) {
        ...
        return {
          pass: pass,
          message: message,
          error: new Error(message + '\n\n' + details)
        };
      }
    };
  }
});

Package Sidebar

Install

npm i jasmine-matcher-errors

Weekly Downloads

2

Version

1.0.0

License

MIT

Last publish

Collaborators

  • deckar01