custom failure message on any jasmine assertion
npm install jasmine-custom-messagejasmine-custom-message
======================
> works with jasmine v1.3 (for work with jasmine v2 see jasmine2-custom-message)
This script makes it possible to use your own failure message on any jasmine assertion.
#### Example
``js
`
describe('the story', function() {
it('should finish ok', function() {
since('all cats are grey in the dark').
expect('tiger').toEqual('kitty'); // => 'all cats are grey in the dark'
});
});
since
Simple
All the magic happens in function. That returns an object with a property expect. That contains no more than a wrapped jasmine expect function. That returns jasmine expectation object with a specially defined message function. That can produce a custom failure message. That is generating based on a custom message you have supplied to since function as the first argument. That can be a primitive (except null and undefined), a function, or any other object. That is it.
`
#### Example
js
`
describe('test', function() {
it('should be ok', function() {
since(function() {
return {'tiger': 'kitty'};
}).
expect(3).toEqual(4); // => '{"tiger":"kitty"}'
});
});
jasmine-custom-message
Unobtrusive
You can use jasmine as you did before, since does not replace global jasmine expect function.
`
#### Example
js
`
describe('test', function() {
it('should be ok', function() {
expect(3).toEqual(4); // => ordinary jasmine message
});
});
this.actual
Powerful
You can use expected and actual value of the assertion in your custom message, by:
* Passing a function, and using and this.expected
#{actual}
* Passing a string, and using and #{expected}
`
#### Example using a function
js
`
describe('test', function() {
it('should be ok', function() {
since(function(expected) {
return this.actual + ' =/= ' + expected;
}).
expect(3).toEqual(4); // => '3 =/= 4'
});
});
`
#### Example using a string
js
`
describe('test', function() {
it('should be ok', function() {
since('#{actual} =/= #{expected}').
expect(3).toEqual(4); // => '3 =/= 4'
});
});
then
Moreover, you can use a promise as an argument of expect or matcher functions. Promise is recognized by method, so be careful if your non-promise object has this method.
`
#### Example (with a little help of protractor)
js
`
describe('test', function() {
it('should be ok', function() {
since(function(expected) {
return this.actual + ' =/= ' + expected;
}).
expect(protractor.promise.fulfilled(3)).toEqual(protractor.promise.fulfilled(4)); // => '3 =/= 4'
});
});
`
Front-end usage
* install the bower package from github
`
bower install jasmine-custom-message --save-dev
jasmine-custom-message.js
* include into your HTML file next to jasmine script
`html
`
`
Node.js usage
* install the bower package
`
bower install jasmine-custom-message --save-dev
`
or npm package
`
npm install jasmine-custom-message --save-dev
`
* require it in your spec file before your tests
js
`
require('jasmine-custom-message');
v0.8.0
Change log
- 2015.08.05 - Be careful of objects with then method, since they are treated as promises
protractor
* fixed issue with custom failure messages on promised assertions
* implemented "format string" functionality: #{actual} and #{expected}
* configured environment
protractor
* corrected displaying of colors in tests running through
v0.7.0
* updated specs
- 2014.10.23
v0.6.0
* fixed issue with custom failure messages on inverse assertions
* updated specs
- 2014.01.18 - BROKEN COMPATIBILITY!
since
* all the magic moved into newly introduced function
v0.5.0
* restored automatic initiation of the script upon inclusion (browser) or require (Node.js)
* cleaned specs
- 2014.01.15
it
* added support for nested message functions
* dropped automatic wrapping of jasmine and expect functions in browsers
v0.2.0
* added specs for Node.js
* added specs for browsers
* registered bower package
* made disambiguation and readability improvements
- 2014.01.10 - BROKEN COMPATIBILITY!
it
* custom messages is supplied as the third argument for jasmine function
v0.1.0
- 2014.01.08
v0.9.0` - some new features (based on requests from Issues)
* the first functional version
Release plan