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

@@ -7,11 +7,30 @@ describe("toBe", function() {
expect(result.pass).toBe(true);
});
it("fails when actual !== expected", function() {
it("fails with no message when actual !== expected", function() {
var matcher = jasmineUnderTest.matchers.toBe(),
result;
result = matcher.compare(1, 2);
expect(result.pass).toBe(false);
expect(result.message).toBeUndefined();
});
it("fails with a custom message when expected is an array", function() {
var matcher = jasmineUnderTest.matchers.toBe(),
result;
result = matcher.compare([1], [1]);
expect(result.pass).toBe(false);
expect(result.message).toBe("Expected [ 1 ] to be [ 1 ]. Tip: To check for deep equality, use .toEqual() instead of .toBe().")
});
it("fails with a custom message when expected is an object", function() {
var matcher = jasmineUnderTest.matchers.toBe(),
result;
result = matcher.compare({foo: "bar"}, {foo: "bar"});
expect(result.pass).toBe(false);
expect(result.message).toBe("Expected Object({ foo: 'bar' }) to be Object({ foo: 'bar' }). Tip: To check for deep equality, use .toEqual() instead of .toBe().")
});
});