Merge branch 'tdurtschi-master'

- Merges #1616 from @tdurtshi
- Fixes #1614
This commit is contained in:
Gregg Van Hove
2018-10-22 10:57:50 -07:00
3 changed files with 67 additions and 12 deletions

View File

@@ -3765,7 +3765,7 @@ getJasmineRequireObj().ObjectPath = function(j$) {
return ObjectPath; return ObjectPath;
}; };
getJasmineRequireObj().toBe = function() { getJasmineRequireObj().toBe = function(j$) {
/** /**
* {@link expect} the actual value to be `===` to the expected value. * {@link expect} the actual value to be `===` to the expected value.
* @function * @function
@@ -3774,12 +3774,20 @@ getJasmineRequireObj().toBe = function() {
* @example * @example
* expect(thing).toBe(realThing); * expect(thing).toBe(realThing);
*/ */
function toBe() { function toBe(util) {
var tip = ' Tip: To check for deep equality, use .toEqual() instead of .toBe().';
return { return {
compare: function(actual, expected) { compare: function(actual, expected) {
return { var result = {
pass: actual === expected pass: actual === expected,
}; };
if (typeof expected === 'object') {
result.message = util.buildFailureMessage('toBe', result.pass, actual, expected) + tip;
}
return result;
} }
}; };
} }

View File

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

View File

@@ -1,4 +1,4 @@
getJasmineRequireObj().toBe = function() { getJasmineRequireObj().toBe = function(j$) {
/** /**
* {@link expect} the actual value to be `===` to the expected value. * {@link expect} the actual value to be `===` to the expected value.
* @function * @function
@@ -7,12 +7,20 @@ getJasmineRequireObj().toBe = function() {
* @example * @example
* expect(thing).toBe(realThing); * expect(thing).toBe(realThing);
*/ */
function toBe() { function toBe(util) {
var tip = ' Tip: To check for deep equality, use .toEqual() instead of .toBe().';
return { return {
compare: function(actual, expected) { compare: function(actual, expected) {
return { var result = {
pass: actual === expected pass: actual === expected,
}; };
if (typeof expected === 'object') {
result.message = util.buildFailureMessage('toBe', result.pass, actual, expected) + tip;
}
return result;
} }
}; };
} }