matchers.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _jestDiff = require('jest-diff');
  6. var _jestDiff2 = _interopRequireDefault(_jestDiff);
  7. var _jestGetType = require('jest-get-type');
  8. var _jestGetType2 = _interopRequireDefault(_jestGetType);
  9. var _jestRegexUtil = require('jest-regex-util');
  10. var _jestMatcherUtils = require('jest-matcher-utils');
  11. var _utils = require('./utils');
  12. var _jasmine_utils = require('./jasmine_utils');
  13. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14. const matchers = {
  15. toBe(received, expected) {
  16. const comment = 'Object.is equality';
  17. const pass = Object.is(received, expected);
  18. const message = pass ? () => (0, _jestMatcherUtils.matcherHint)('.not.toBe', undefined, undefined, {
  19. comment
  20. }) + '\n\n' + `Expected value to not be:\n` + ` ${(0, _jestMatcherUtils.printExpected)(expected)}\n` + `Received:\n` + ` ${(0, _jestMatcherUtils.printReceived)(received)}` : () => {
  21. const suggestToEqual = (0, _jestGetType2.default)(received) === (0, _jestGetType2.default)(expected) && ((0, _jestGetType2.default)(received) === 'object' || (0, _jestGetType2.default)(expected) === 'array') && (0, _jasmine_utils.equals)(received, expected, [_utils.iterableEquality]);
  22. const diffString = (0, _jestDiff2.default)(expected, received, {
  23. expand: this.expand
  24. });
  25. return (0, _jestMatcherUtils.matcherHint)('.toBe', undefined, undefined, {
  26. comment
  27. }) + '\n\n' + `Expected value to be:\n` + ` ${(0, _jestMatcherUtils.printExpected)(expected)}\n` + `Received:\n` + ` ${(0, _jestMatcherUtils.printReceived)(received)}` + (diffString ? `\n\nDifference:\n\n${diffString}` : '') + (suggestToEqual ? ` ${_jestMatcherUtils.SUGGEST_TO_EQUAL}` : '');
  28. };
  29. // Passing the the actual and expected objects so that a custom reporter
  30. // could access them, for example in order to display a custom visual diff,
  31. // or create a different error message
  32. return { actual: received, expected, message, name: 'toBe', pass };
  33. },
  34. toBeCloseTo(actual, expected) {
  35. let precision = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2;
  36. const secondArgument = arguments.length === 3 ? 'precision' : null;
  37. (0, _jestMatcherUtils.ensureNumbers)(actual, expected, '.toBeCloseTo');
  38. const pass = Math.abs(expected - actual) < Math.pow(10, -precision) / 2;
  39. const message = pass ? () => (0, _jestMatcherUtils.matcherHint)('.not.toBeCloseTo', undefined, undefined, {
  40. secondArgument
  41. }) + '\n\n' + `Expected value not to be close to (with ${(0, _jestMatcherUtils.printExpected)(precision)}-digit precision):\n` + ` ${(0, _jestMatcherUtils.printExpected)(expected)}\n` + `Received:\n` + ` ${(0, _jestMatcherUtils.printReceived)(actual)}` : () => (0, _jestMatcherUtils.matcherHint)('.toBeCloseTo', undefined, undefined, {
  42. secondArgument
  43. }) + '\n\n' + `Expected value to be close to (with ${(0, _jestMatcherUtils.printExpected)(precision)}-digit precision):\n` + ` ${(0, _jestMatcherUtils.printExpected)(expected)}\n` + `Received:\n` + ` ${(0, _jestMatcherUtils.printReceived)(actual)}`;
  44. return { message, pass };
  45. },
  46. toBeDefined(actual, expected) {
  47. (0, _jestMatcherUtils.ensureNoExpected)(expected, '.toBeDefined');
  48. const pass = actual !== void 0;
  49. const message = pass ? () => (0, _jestMatcherUtils.matcherHint)('.not.toBeDefined', 'received', '') + '\n\n' + `Expected value not to be defined, instead received\n` + ` ${(0, _jestMatcherUtils.printReceived)(actual)}` : () => (0, _jestMatcherUtils.matcherHint)('.toBeDefined', 'received', '') + '\n\n' + `Expected value to be defined, instead received\n` + ` ${(0, _jestMatcherUtils.printReceived)(actual)}`;
  50. return { message, pass };
  51. },
  52. toBeFalsy(actual, expected) {
  53. (0, _jestMatcherUtils.ensureNoExpected)(expected, '.toBeFalsy');
  54. const pass = !actual;
  55. const message = pass ? () => (0, _jestMatcherUtils.matcherHint)('.not.toBeFalsy', 'received', '') + '\n\n' + `Expected value not to be falsy, instead received\n` + ` ${(0, _jestMatcherUtils.printReceived)(actual)}` : () => (0, _jestMatcherUtils.matcherHint)('.toBeFalsy', 'received', '') + '\n\n' + `Expected value to be falsy, instead received\n` + ` ${(0, _jestMatcherUtils.printReceived)(actual)}`;
  56. return { message, pass };
  57. },
  58. toBeGreaterThan(actual, expected) {
  59. (0, _jestMatcherUtils.ensureNumbers)(actual, expected, '.toBeGreaterThan');
  60. const pass = actual > expected;
  61. const message = pass ? () => (0, _jestMatcherUtils.matcherHint)('.not.toBeGreaterThan') + '\n\n' + `Expected value not to be greater than:\n` + ` ${(0, _jestMatcherUtils.printExpected)(expected)}\n` + `Received:\n` + ` ${(0, _jestMatcherUtils.printReceived)(actual)}` : () => (0, _jestMatcherUtils.matcherHint)('.toBeGreaterThan') + '\n\n' + `Expected value to be greater than:\n` + ` ${(0, _jestMatcherUtils.printExpected)(expected)}\n` + `Received:\n` + ` ${(0, _jestMatcherUtils.printReceived)(actual)}`;
  62. return { message, pass };
  63. },
  64. toBeGreaterThanOrEqual(actual, expected) {
  65. (0, _jestMatcherUtils.ensureNumbers)(actual, expected, '.toBeGreaterThanOrEqual');
  66. const pass = actual >= expected;
  67. const message = pass ? () => (0, _jestMatcherUtils.matcherHint)('.not.toBeGreaterThanOrEqual') + '\n\n' + `Expected value not to be greater than or equal:\n` + ` ${(0, _jestMatcherUtils.printExpected)(expected)}\n` + `Received:\n` + ` ${(0, _jestMatcherUtils.printReceived)(actual)}` : () => (0, _jestMatcherUtils.matcherHint)('.toBeGreaterThanOrEqual') + '\n\n' + `Expected value to be greater than or equal:\n` + ` ${(0, _jestMatcherUtils.printExpected)(expected)}\n` + `Received:\n` + ` ${(0, _jestMatcherUtils.printReceived)(actual)}`;
  68. return { message, pass };
  69. },
  70. toBeInstanceOf(received, constructor) {
  71. const constType = (0, _jestGetType2.default)(constructor);
  72. if (constType !== 'function') {
  73. throw new Error((0, _jestMatcherUtils.matcherHint)('[.not].toBeInstanceOf', 'value', 'constructor') + `\n\n` + `Expected constructor to be a function. Instead got:\n` + ` ${(0, _jestMatcherUtils.printExpected)(constType)}`);
  74. }
  75. const pass = received instanceof constructor;
  76. const message = pass ? () => (0, _jestMatcherUtils.matcherHint)('.not.toBeInstanceOf', 'value', 'constructor') + '\n\n' + `Expected value not to be an instance of:\n` + ` ${(0, _jestMatcherUtils.printExpected)(constructor.name || constructor)}\n` + `Received:\n` + ` ${(0, _jestMatcherUtils.printReceived)(received)}\n` : () => (0, _jestMatcherUtils.matcherHint)('.toBeInstanceOf', 'value', 'constructor') + '\n\n' + `Expected value to be an instance of:\n` + ` ${(0, _jestMatcherUtils.printExpected)(constructor.name || constructor)}\n` + `Received:\n` + ` ${(0, _jestMatcherUtils.printReceived)(received)}\n` + `Constructor:\n` + ` ${(0, _jestMatcherUtils.printReceived)(received.constructor && received.constructor.name)}`;
  77. return { message, pass };
  78. },
  79. toBeLessThan(actual, expected) {
  80. (0, _jestMatcherUtils.ensureNumbers)(actual, expected, '.toBeLessThan');
  81. const pass = actual < expected;
  82. const message = pass ? () => (0, _jestMatcherUtils.matcherHint)('.not.toBeLessThan') + '\n\n' + `Expected value not to be less than:\n` + ` ${(0, _jestMatcherUtils.printExpected)(expected)}\n` + `Received:\n` + ` ${(0, _jestMatcherUtils.printReceived)(actual)}` : () => (0, _jestMatcherUtils.matcherHint)('.toBeLessThan') + '\n\n' + `Expected value to be less than:\n` + ` ${(0, _jestMatcherUtils.printExpected)(expected)}\n` + `Received:\n` + ` ${(0, _jestMatcherUtils.printReceived)(actual)}`;
  83. return { message, pass };
  84. },
  85. toBeLessThanOrEqual(actual, expected) {
  86. (0, _jestMatcherUtils.ensureNumbers)(actual, expected, '.toBeLessThanOrEqual');
  87. const pass = actual <= expected;
  88. const message = pass ? () => (0, _jestMatcherUtils.matcherHint)('.not.toBeLessThanOrEqual') + '\n\n' + `Expected value not to be less than or equal:\n` + ` ${(0, _jestMatcherUtils.printExpected)(expected)}\n` + `Received:\n` + ` ${(0, _jestMatcherUtils.printReceived)(actual)}` : () => (0, _jestMatcherUtils.matcherHint)('.toBeLessThanOrEqual') + '\n\n' + `Expected value to be less than or equal:\n` + ` ${(0, _jestMatcherUtils.printExpected)(expected)}\n` + `Received:\n` + ` ${(0, _jestMatcherUtils.printReceived)(actual)}`;
  89. return { message, pass };
  90. },
  91. toBeNaN(actual, expected) {
  92. (0, _jestMatcherUtils.ensureNoExpected)(expected, '.toBeNaN');
  93. const pass = Number.isNaN(actual);
  94. const message = pass ? () => (0, _jestMatcherUtils.matcherHint)('.not.toBeNaN', 'received', '') + '\n\n' + `Expected value not to be NaN, instead received\n` + ` ${(0, _jestMatcherUtils.printReceived)(actual)}` : () => (0, _jestMatcherUtils.matcherHint)('.toBeNaN', 'received', '') + '\n\n' + `Expected value to be NaN, instead received\n` + ` ${(0, _jestMatcherUtils.printReceived)(actual)}`;
  95. return { message, pass };
  96. },
  97. toBeNull(actual, expected) {
  98. (0, _jestMatcherUtils.ensureNoExpected)(expected, '.toBeNull');
  99. const pass = actual === null;
  100. const message = pass ? () => (0, _jestMatcherUtils.matcherHint)('.not.toBeNull', 'received', '') + '\n\n' + `Expected value not to be null, instead received\n` + ` ${(0, _jestMatcherUtils.printReceived)(actual)}` : () => (0, _jestMatcherUtils.matcherHint)('.toBeNull', 'received', '') + '\n\n' + `Expected value to be null, instead received\n` + ` ${(0, _jestMatcherUtils.printReceived)(actual)}`;
  101. return { message, pass };
  102. },
  103. toBeTruthy(actual, expected) {
  104. (0, _jestMatcherUtils.ensureNoExpected)(expected, '.toBeTruthy');
  105. const pass = !!actual;
  106. const message = pass ? () => (0, _jestMatcherUtils.matcherHint)('.not.toBeTruthy', 'received', '') + '\n\n' + `Expected value not to be truthy, instead received\n` + ` ${(0, _jestMatcherUtils.printReceived)(actual)}` : () => (0, _jestMatcherUtils.matcherHint)('.toBeTruthy', 'received', '') + '\n\n' + `Expected value to be truthy, instead received\n` + ` ${(0, _jestMatcherUtils.printReceived)(actual)}`;
  107. return { message, pass };
  108. },
  109. toBeUndefined(actual, expected) {
  110. (0, _jestMatcherUtils.ensureNoExpected)(expected, '.toBeUndefined');
  111. const pass = actual === void 0;
  112. const message = pass ? () => (0, _jestMatcherUtils.matcherHint)('.not.toBeUndefined', 'received', '') + '\n\n' + `Expected value not to be undefined, instead received\n` + ` ${(0, _jestMatcherUtils.printReceived)(actual)}` : () => (0, _jestMatcherUtils.matcherHint)('.toBeUndefined', 'received', '') + '\n\n' + `Expected value to be undefined, instead received\n` + ` ${(0, _jestMatcherUtils.printReceived)(actual)}`;
  113. return { message, pass };
  114. },
  115. toContain(collection, value) {
  116. const collectionType = (0, _jestGetType2.default)(collection);
  117. let converted = null;
  118. if (Array.isArray(collection) || typeof collection === 'string') {
  119. // strings have `indexOf` so we don't need to convert
  120. // arrays have `indexOf` and we don't want to make a copy
  121. converted = collection;
  122. } else {
  123. try {
  124. converted = Array.from(collection);
  125. } catch (e) {
  126. throw new Error((0, _jestMatcherUtils.matcherHint)('[.not].toContainEqual', 'collection', 'value') + '\n\n' + `Expected ${(0, _jestMatcherUtils.RECEIVED_COLOR)('collection')} to be an array-like structure.\n` + (0, _jestMatcherUtils.printWithType)('Received', collection, _jestMatcherUtils.printReceived));
  127. }
  128. }
  129. // At this point, we're either a string or an Array,
  130. // which was converted from an array-like structure.
  131. const pass = converted.indexOf(value) != -1;
  132. const message = pass ? () => (0, _jestMatcherUtils.matcherHint)('.not.toContain', collectionType, 'value') + '\n\n' + `Expected ${collectionType}:\n` + ` ${(0, _jestMatcherUtils.printReceived)(collection)}\n` + `Not to contain value:\n` + ` ${(0, _jestMatcherUtils.printExpected)(value)}\n` : () => (0, _jestMatcherUtils.matcherHint)('.toContain', collectionType, 'value') + '\n\n' + `Expected ${collectionType}:\n` + ` ${(0, _jestMatcherUtils.printReceived)(collection)}\n` + `To contain value:\n` + ` ${(0, _jestMatcherUtils.printExpected)(value)}`;
  133. return { message, pass };
  134. },
  135. toContainEqual(collection, value) {
  136. const collectionType = (0, _jestGetType2.default)(collection);
  137. let converted = null;
  138. if (Array.isArray(collection)) {
  139. converted = collection;
  140. } else {
  141. try {
  142. converted = Array.from(collection);
  143. } catch (e) {
  144. throw new Error((0, _jestMatcherUtils.matcherHint)('[.not].toContainEqual', 'collection', 'value') + '\n\n' + `Expected ${(0, _jestMatcherUtils.RECEIVED_COLOR)('collection')} to be an array-like structure.\n` + (0, _jestMatcherUtils.printWithType)('Received', collection, _jestMatcherUtils.printReceived));
  145. }
  146. }
  147. const pass = converted.findIndex(item => (0, _jasmine_utils.equals)(item, value, [_utils.iterableEquality])) !== -1;
  148. const message = pass ? () => (0, _jestMatcherUtils.matcherHint)('.not.toContainEqual', collectionType, 'value') + '\n\n' + `Expected ${collectionType}:\n` + ` ${(0, _jestMatcherUtils.printReceived)(collection)}\n` + `Not to contain a value equal to:\n` + ` ${(0, _jestMatcherUtils.printExpected)(value)}\n` : () => (0, _jestMatcherUtils.matcherHint)('.toContainEqual', collectionType, 'value') + '\n\n' + `Expected ${collectionType}:\n` + ` ${(0, _jestMatcherUtils.printReceived)(collection)}\n` + `To contain a value equal to:\n` + ` ${(0, _jestMatcherUtils.printExpected)(value)}`;
  149. return { message, pass };
  150. },
  151. toEqual(received, expected) {
  152. const pass = (0, _jasmine_utils.equals)(received, expected, [_utils.iterableEquality]);
  153. const message = pass ? () => (0, _jestMatcherUtils.matcherHint)('.not.toEqual') + '\n\n' + `Expected value to not equal:\n` + ` ${(0, _jestMatcherUtils.printExpected)(expected)}\n` + `Received:\n` + ` ${(0, _jestMatcherUtils.printReceived)(received)}` : () => {
  154. const diffString = (0, _jestDiff2.default)(expected, received, {
  155. expand: this.expand
  156. });
  157. return (0, _jestMatcherUtils.matcherHint)('.toEqual') + '\n\n' + `Expected value to equal:\n` + ` ${(0, _jestMatcherUtils.printExpected)(expected)}\n` + `Received:\n` + ` ${(0, _jestMatcherUtils.printReceived)(received)}` + (diffString ? `\n\nDifference:\n\n${diffString}` : '');
  158. };
  159. // Passing the the actual and expected objects so that a custom reporter
  160. // could access them, for example in order to display a custom visual diff,
  161. // or create a different error message
  162. return { actual: received, expected, message, name: 'toEqual', pass };
  163. },
  164. toHaveLength(received, length) {
  165. if (typeof received !== 'string' && (!received || typeof received.length !== 'number')) {
  166. throw new Error((0, _jestMatcherUtils.matcherHint)('[.not].toHaveLength', 'received', 'length') + '\n\n' + `Expected value to have a 'length' property that is a number. ` + `Received:\n` + ` ${(0, _jestMatcherUtils.printReceived)(received)}\n` + (received ? `received.length:\n ${(0, _jestMatcherUtils.printReceived)(received.length)}` : ''));
  167. }
  168. const pass = received.length === length;
  169. const message = pass ? () => (0, _jestMatcherUtils.matcherHint)('.not.toHaveLength', 'received', 'length') + '\n\n' + `Expected value to not have length:\n` + ` ${(0, _jestMatcherUtils.printExpected)(length)}\n` + `Received:\n` + ` ${(0, _jestMatcherUtils.printReceived)(received)}\n` + `received.length:\n` + ` ${(0, _jestMatcherUtils.printReceived)(received.length)}` : () => (0, _jestMatcherUtils.matcherHint)('.toHaveLength', 'received', 'length') + '\n\n' + `Expected value to have length:\n` + ` ${(0, _jestMatcherUtils.printExpected)(length)}\n` + `Received:\n` + ` ${(0, _jestMatcherUtils.printReceived)(received)}\n` + `received.length:\n` + ` ${(0, _jestMatcherUtils.printReceived)(received.length)}`;
  170. return { message, pass };
  171. },
  172. toHaveProperty(object, keyPath, value) {
  173. const valuePassed = arguments.length === 3;
  174. const secondArgument = valuePassed ? 'value' : null;
  175. if (!object && typeof object !== 'string' && typeof object !== 'number') {
  176. throw new Error((0, _jestMatcherUtils.matcherHint)('[.not].toHaveProperty', 'object', 'path', {
  177. secondArgument
  178. }) + '\n\n' + `Expected ${(0, _jestMatcherUtils.RECEIVED_COLOR)('object')} to be an object. Received:\n` + ` ${(0, _jestGetType2.default)(object)}: ${(0, _jestMatcherUtils.printReceived)(object)}`);
  179. }
  180. const keyPathType = (0, _jestGetType2.default)(keyPath);
  181. if (keyPathType !== 'string' && keyPathType !== 'array') {
  182. throw new Error((0, _jestMatcherUtils.matcherHint)('[.not].toHaveProperty', 'object', 'path', {
  183. secondArgument
  184. }) + '\n\n' + `Expected ${(0, _jestMatcherUtils.EXPECTED_COLOR)('path')} to be a string or an array. Received:\n` + ` ${(0, _jestGetType2.default)(keyPath)}: ${(0, _jestMatcherUtils.printReceived)(keyPath)}`);
  185. }
  186. const result = (0, _utils.getPath)(object, keyPath);
  187. const lastTraversedObject = result.lastTraversedObject,
  188. hasEndProp = result.hasEndProp;
  189. const pass = valuePassed ? (0, _jasmine_utils.equals)(result.value, value, [_utils.iterableEquality]) : hasEndProp;
  190. const traversedPath = result.traversedPath.join('.');
  191. const message = pass ? () => (0, _jestMatcherUtils.matcherHint)('.not.toHaveProperty', 'object', 'path', {
  192. secondArgument
  193. }) + '\n\n' + `Expected the object:\n` + ` ${(0, _jestMatcherUtils.printReceived)(object)}\n` + `Not to have a nested property:\n` + ` ${(0, _jestMatcherUtils.printExpected)(keyPath)}\n` + (valuePassed ? `With a value of:\n ${(0, _jestMatcherUtils.printExpected)(value)}\n` : '') : () => {
  194. const diffString = valuePassed && hasEndProp ? (0, _jestDiff2.default)(value, result.value, { expand: this.expand }) : '';
  195. return (0, _jestMatcherUtils.matcherHint)('.toHaveProperty', 'object', 'path', {
  196. secondArgument
  197. }) + '\n\n' + `Expected the object:\n` + ` ${(0, _jestMatcherUtils.printReceived)(object)}\n` + `To have a nested property:\n` + ` ${(0, _jestMatcherUtils.printExpected)(keyPath)}\n` + (valuePassed ? `With a value of:\n ${(0, _jestMatcherUtils.printExpected)(value)}\n` : '') + (hasEndProp ? `Received:\n` + ` ${(0, _jestMatcherUtils.printReceived)(result.value)}` + (diffString ? `\n\nDifference:\n\n${diffString}` : '') : traversedPath ? `Received:\n ${(0, _jestMatcherUtils.RECEIVED_COLOR)('object')}.${traversedPath}: ${(0, _jestMatcherUtils.printReceived)(lastTraversedObject)}` : '');
  198. };
  199. if (pass === undefined) {
  200. throw new Error('pass must be initialized');
  201. }
  202. return { message, pass };
  203. },
  204. toMatch(received, expected) {
  205. if (typeof received !== 'string') {
  206. throw new Error((0, _jestMatcherUtils.matcherHint)('[.not].toMatch', 'string', 'expected') + '\n\n' + `${(0, _jestMatcherUtils.RECEIVED_COLOR)('string')} value must be a string.\n` + (0, _jestMatcherUtils.printWithType)('Received', received, _jestMatcherUtils.printReceived));
  207. }
  208. if (!(expected instanceof RegExp) && !(typeof expected === 'string')) {
  209. throw new Error((0, _jestMatcherUtils.matcherHint)('[.not].toMatch', 'string', 'expected') + '\n\n' + `${(0, _jestMatcherUtils.EXPECTED_COLOR)('expected')} value must be a string or a regular expression.\n` + (0, _jestMatcherUtils.printWithType)('Expected', expected, _jestMatcherUtils.printExpected));
  210. }
  211. const pass = new RegExp(typeof expected === 'string' ? (0, _jestRegexUtil.escapeStrForRegex)(expected) : expected).test(received);
  212. const message = pass ? () => (0, _jestMatcherUtils.matcherHint)('.not.toMatch') + `\n\nExpected value not to match:\n` + ` ${(0, _jestMatcherUtils.printExpected)(expected)}` + `\nReceived:\n` + ` ${(0, _jestMatcherUtils.printReceived)(received)}` : () => (0, _jestMatcherUtils.matcherHint)('.toMatch') + `\n\nExpected value to match:\n` + ` ${(0, _jestMatcherUtils.printExpected)(expected)}` + `\nReceived:\n` + ` ${(0, _jestMatcherUtils.printReceived)(received)}`;
  213. return { message, pass };
  214. },
  215. toMatchObject(receivedObject, expectedObject) {
  216. if (typeof receivedObject !== 'object' || receivedObject === null) {
  217. throw new Error((0, _jestMatcherUtils.matcherHint)('[.not].toMatchObject', 'object', 'expected') + '\n\n' + `${(0, _jestMatcherUtils.RECEIVED_COLOR)('received')} value must be an object.\n` + (0, _jestMatcherUtils.printWithType)('Received', receivedObject, _jestMatcherUtils.printReceived));
  218. }
  219. if (typeof expectedObject !== 'object' || expectedObject === null) {
  220. throw new Error((0, _jestMatcherUtils.matcherHint)('[.not].toMatchObject', 'object', 'expected') + '\n\n' + `${(0, _jestMatcherUtils.EXPECTED_COLOR)('expected')} value must be an object.\n` + (0, _jestMatcherUtils.printWithType)('Expected', expectedObject, _jestMatcherUtils.printExpected));
  221. }
  222. const pass = (0, _jasmine_utils.equals)(receivedObject, expectedObject, [_utils.iterableEquality, _utils.subsetEquality]);
  223. const message = pass ? () => (0, _jestMatcherUtils.matcherHint)('.not.toMatchObject') + `\n\nExpected value not to match object:\n` + ` ${(0, _jestMatcherUtils.printExpected)(expectedObject)}` + `\nReceived:\n` + ` ${(0, _jestMatcherUtils.printReceived)(receivedObject)}` : () => {
  224. const diffString = (0, _jestDiff2.default)(expectedObject, (0, _utils.getObjectSubset)(receivedObject, expectedObject), {
  225. expand: this.expand
  226. });
  227. return (0, _jestMatcherUtils.matcherHint)('.toMatchObject') + `\n\nExpected value to match object:\n` + ` ${(0, _jestMatcherUtils.printExpected)(expectedObject)}` + `\nReceived:\n` + ` ${(0, _jestMatcherUtils.printReceived)(receivedObject)}` + (diffString ? `\nDifference:\n${diffString}` : '');
  228. };
  229. return { message, pass };
  230. }
  231. }; /**
  232. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  233. *
  234. * This source code is licensed under the MIT license found in the
  235. * LICENSE file in the root directory of this source tree.
  236. *
  237. *
  238. */
  239. exports.default = matchers;