Add custom message for toBe() matcher when object equality check fails

This commit is contained in:
Teagan Durtschi
2018-10-21 12:46:49 -04:00
parent 440b6934aa
commit 7cbedcdda7
2 changed files with 26 additions and 3 deletions

View File

@@ -1,4 +1,4 @@
getJasmineRequireObj().toBe = function() {
getJasmineRequireObj().toBe = function($j) {
/**
* {@link expect} the actual value to be `===` to the expected value.
* @function
@@ -8,10 +8,14 @@ getJasmineRequireObj().toBe = function() {
* expect(thing).toBe(realThing);
*/
function toBe() {
return {
compare: function(actual, expected) {
var customMessage = 'Expected ' + $j.pp(expected) + ' to be ' + $j.pp(actual) + '. Tip: To check for deep equality, use .toEqual() instead of .toBe().';
return {
pass: actual === expected
pass: actual === expected,
message: typeof expected === 'object' ? customMessage : undefined,
};
}
};