Files
jasmine/spec/core/matchers/toBeSpec.js
Steve Gravrock 434575f49d Use one declaration per statement
The old style of merging all of a function's variable declarations into
a single statement made some sense back in the days of var, but there's
no reason to keep doing it now that we use const and let.
2026-03-11 06:30:46 -07:00

88 lines
3.3 KiB
JavaScript

describe('toBe', function() {
it('passes with no message when actual === expected', function() {
const matchersUtil = new privateUnderTest.MatchersUtil();
const matcher = privateUnderTest.matchers.toBe(matchersUtil);
const result = matcher.compare(1, 1);
expect(result.pass).toBe(true);
});
it('passes with a custom message when expected is an array', function() {
const matchersUtil = new privateUnderTest.MatchersUtil({
pp: privateUnderTest.makePrettyPrinter()
});
const matcher = privateUnderTest.matchers.toBe(matchersUtil);
const array = [1];
const 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() {
const matchersUtil = new privateUnderTest.MatchersUtil({
pp: privateUnderTest.makePrettyPrinter()
});
const matcher = privateUnderTest.matchers.toBe(matchersUtil);
const obj = { foo: 'bar' };
const 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() {
const matchersUtil = new privateUnderTest.MatchersUtil();
const matcher = privateUnderTest.matchers.toBe(matchersUtil);
const 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() {
const matchersUtil = new privateUnderTest.MatchersUtil({
pp: privateUnderTest.makePrettyPrinter()
});
const matcher = privateUnderTest.matchers.toBe(matchersUtil);
const 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() {
const matchersUtil = new privateUnderTest.MatchersUtil({
pp: privateUnderTest.makePrettyPrinter()
});
const matcher = privateUnderTest.matchers.toBe(matchersUtil);
const 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()."
);
});
it('works with custom object formatters when expected is an object', function() {
const formatter = function(x) {
return '<' + x.foo + '>';
};
const prettyPrinter = privateUnderTest.makePrettyPrinter([formatter]);
const matchersUtil = new privateUnderTest.MatchersUtil({
pp: prettyPrinter
});
const matcher = privateUnderTest.matchers.toBe(matchersUtil);
const result = matcher.compare({ foo: 'bar' }, { foo: 'bar' });
expect(result.pass).toBe(false);
expect(result.message).toBe(
'Expected <bar> to be <bar>. Tip: To check for deep equality, use .toEqual() instead of .toBe().'
);
});
});