jasmine-matcher-errors
v1.0.0
Published
Customize the error message reported by a custom jasmine matcher.
Downloads
7
Maintainers
Readme
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.
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.
Setup
jasmine-node
- Install from npm.
npm install --save-dev jasmine-matcher-errors
- Include in your custom matchers.
require('jasmine-matcher-errors')
jasmine
- Install from bower.
bower install --save-dev jasmine-matcher-errors
- 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)
};
}
};
}
});