版博士V2.0程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

1346 linhas
43 KiB

  1. import { getColors, stringify, isObject, assertTypes } from '@vitest/utils';
  2. export { setupColors } from '@vitest/utils';
  3. import { unifiedDiff } from '@vitest/utils/diff';
  4. import { AssertionError, util } from 'chai';
  5. import { isMockFunction } from '@vitest/spy';
  6. const MATCHERS_OBJECT = Symbol.for("matchers-object");
  7. const JEST_MATCHERS_OBJECT = Symbol.for("$$jest-matchers-object");
  8. const GLOBAL_EXPECT = Symbol.for("expect-global");
  9. if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) {
  10. const globalState = /* @__PURE__ */ new WeakMap();
  11. const matchers = /* @__PURE__ */ Object.create(null);
  12. Object.defineProperty(globalThis, MATCHERS_OBJECT, {
  13. get: () => globalState
  14. });
  15. Object.defineProperty(globalThis, JEST_MATCHERS_OBJECT, {
  16. configurable: true,
  17. get: () => ({
  18. state: globalState.get(globalThis[GLOBAL_EXPECT]),
  19. matchers
  20. })
  21. });
  22. }
  23. const getState = (expect) => globalThis[MATCHERS_OBJECT].get(expect);
  24. const setState = (state, expect) => {
  25. const map = globalThis[MATCHERS_OBJECT];
  26. const current = map.get(expect) || {};
  27. Object.assign(current, state);
  28. map.set(expect, current);
  29. };
  30. function getMatcherUtils() {
  31. const c = () => getColors();
  32. const EXPECTED_COLOR = c().green;
  33. const RECEIVED_COLOR = c().red;
  34. const INVERTED_COLOR = c().inverse;
  35. const BOLD_WEIGHT = c().bold;
  36. const DIM_COLOR = c().dim;
  37. function matcherHint(matcherName, received = "received", expected = "expected", options = {}) {
  38. const {
  39. comment = "",
  40. isDirectExpectCall = false,
  41. isNot = false,
  42. promise = "",
  43. secondArgument = "",
  44. expectedColor = EXPECTED_COLOR,
  45. receivedColor = RECEIVED_COLOR,
  46. secondArgumentColor = EXPECTED_COLOR
  47. } = options;
  48. let hint = "";
  49. let dimString = "expect";
  50. if (!isDirectExpectCall && received !== "") {
  51. hint += DIM_COLOR(`${dimString}(`) + receivedColor(received);
  52. dimString = ")";
  53. }
  54. if (promise !== "") {
  55. hint += DIM_COLOR(`${dimString}.`) + promise;
  56. dimString = "";
  57. }
  58. if (isNot) {
  59. hint += `${DIM_COLOR(`${dimString}.`)}not`;
  60. dimString = "";
  61. }
  62. if (matcherName.includes(".")) {
  63. dimString += matcherName;
  64. } else {
  65. hint += DIM_COLOR(`${dimString}.`) + matcherName;
  66. dimString = "";
  67. }
  68. if (expected === "") {
  69. dimString += "()";
  70. } else {
  71. hint += DIM_COLOR(`${dimString}(`) + expectedColor(expected);
  72. if (secondArgument)
  73. hint += DIM_COLOR(", ") + secondArgumentColor(secondArgument);
  74. dimString = ")";
  75. }
  76. if (comment !== "")
  77. dimString += ` // ${comment}`;
  78. if (dimString !== "")
  79. hint += DIM_COLOR(dimString);
  80. return hint;
  81. }
  82. const SPACE_SYMBOL = "\xB7";
  83. const replaceTrailingSpaces = (text) => text.replace(/\s+$/gm, (spaces) => SPACE_SYMBOL.repeat(spaces.length));
  84. const printReceived = (object) => RECEIVED_COLOR(replaceTrailingSpaces(stringify(object)));
  85. const printExpected = (value) => EXPECTED_COLOR(replaceTrailingSpaces(stringify(value)));
  86. return {
  87. EXPECTED_COLOR,
  88. RECEIVED_COLOR,
  89. INVERTED_COLOR,
  90. BOLD_WEIGHT,
  91. DIM_COLOR,
  92. matcherHint,
  93. printReceived,
  94. printExpected
  95. };
  96. }
  97. function diff(a, b, options) {
  98. const c = getColors();
  99. return unifiedDiff(stringify(b), stringify(a), {
  100. colorDim: c.dim,
  101. colorSuccess: c.green,
  102. colorError: c.red,
  103. showLegend: options == null ? void 0 : options.showLegend
  104. });
  105. }
  106. function equals(a, b, customTesters, strictCheck) {
  107. customTesters = customTesters || [];
  108. return eq(a, b, [], [], customTesters, strictCheck ? hasKey : hasDefinedKey);
  109. }
  110. const functionToString = Function.prototype.toString;
  111. function isAsymmetric(obj) {
  112. return !!obj && typeof obj === "object" && "asymmetricMatch" in obj && isA("Function", obj.asymmetricMatch);
  113. }
  114. function hasAsymmetric(obj, seen = /* @__PURE__ */ new Set()) {
  115. if (seen.has(obj))
  116. return false;
  117. seen.add(obj);
  118. if (isAsymmetric(obj))
  119. return true;
  120. if (Array.isArray(obj))
  121. return obj.some((i) => hasAsymmetric(i, seen));
  122. if (obj instanceof Set)
  123. return Array.from(obj).some((i) => hasAsymmetric(i, seen));
  124. if (isObject(obj))
  125. return Object.values(obj).some((v) => hasAsymmetric(v, seen));
  126. return false;
  127. }
  128. function asymmetricMatch(a, b) {
  129. const asymmetricA = isAsymmetric(a);
  130. const asymmetricB = isAsymmetric(b);
  131. if (asymmetricA && asymmetricB)
  132. return void 0;
  133. if (asymmetricA)
  134. return a.asymmetricMatch(b);
  135. if (asymmetricB)
  136. return b.asymmetricMatch(a);
  137. }
  138. function eq(a, b, aStack, bStack, customTesters, hasKey2) {
  139. let result = true;
  140. const asymmetricResult = asymmetricMatch(a, b);
  141. if (asymmetricResult !== void 0)
  142. return asymmetricResult;
  143. for (let i = 0; i < customTesters.length; i++) {
  144. const customTesterResult = customTesters[i](a, b);
  145. if (customTesterResult !== void 0)
  146. return customTesterResult;
  147. }
  148. if (a instanceof Error && b instanceof Error)
  149. return a.message === b.message;
  150. if (Object.is(a, b))
  151. return true;
  152. if (a === null || b === null)
  153. return a === b;
  154. const className = Object.prototype.toString.call(a);
  155. if (className !== Object.prototype.toString.call(b))
  156. return false;
  157. switch (className) {
  158. case "[object Boolean]":
  159. case "[object String]":
  160. case "[object Number]":
  161. if (typeof a !== typeof b) {
  162. return false;
  163. } else if (typeof a !== "object" && typeof b !== "object") {
  164. return Object.is(a, b);
  165. } else {
  166. return Object.is(a.valueOf(), b.valueOf());
  167. }
  168. case "[object Date]":
  169. return isNaN(a) && isNaN(b) || +a === +b;
  170. case "[object RegExp]":
  171. return a.source === b.source && a.flags === b.flags;
  172. }
  173. if (typeof a !== "object" || typeof b !== "object")
  174. return false;
  175. if (isDomNode(a) && isDomNode(b))
  176. return a.isEqualNode(b);
  177. let length = aStack.length;
  178. while (length--) {
  179. if (aStack[length] === a)
  180. return bStack[length] === b;
  181. else if (bStack[length] === b)
  182. return false;
  183. }
  184. aStack.push(a);
  185. bStack.push(b);
  186. if (className === "[object Array]" && a.length !== b.length)
  187. return false;
  188. const aKeys = keys(a, hasKey2);
  189. let key;
  190. let size = aKeys.length;
  191. if (keys(b, hasKey2).length !== size)
  192. return false;
  193. while (size--) {
  194. key = aKeys[size];
  195. result = hasKey2(b, key) && eq(a[key], b[key], aStack, bStack, customTesters, hasKey2);
  196. if (!result)
  197. return false;
  198. }
  199. aStack.pop();
  200. bStack.pop();
  201. return result;
  202. }
  203. function keys(obj, hasKey2) {
  204. const keys2 = [];
  205. for (const key in obj) {
  206. if (hasKey2(obj, key))
  207. keys2.push(key);
  208. }
  209. return keys2.concat(
  210. Object.getOwnPropertySymbols(obj).filter(
  211. (symbol) => Object.getOwnPropertyDescriptor(obj, symbol).enumerable
  212. )
  213. );
  214. }
  215. function hasDefinedKey(obj, key) {
  216. return hasKey(obj, key) && obj[key] !== void 0;
  217. }
  218. function hasKey(obj, key) {
  219. return Object.prototype.hasOwnProperty.call(obj, key);
  220. }
  221. function isA(typeName, value) {
  222. return Object.prototype.toString.apply(value) === `[object ${typeName}]`;
  223. }
  224. function isDomNode(obj) {
  225. return obj !== null && typeof obj === "object" && typeof obj.nodeType === "number" && typeof obj.nodeName === "string" && typeof obj.isEqualNode === "function";
  226. }
  227. function fnNameFor(func) {
  228. if (func.name)
  229. return func.name;
  230. const matches = functionToString.call(func).match(/^(?:async)?\s*function\s*\*?\s*([\w$]+)\s*\(/);
  231. return matches ? matches[1] : "<anonymous>";
  232. }
  233. function getPrototype(obj) {
  234. if (Object.getPrototypeOf)
  235. return Object.getPrototypeOf(obj);
  236. if (obj.constructor.prototype === obj)
  237. return null;
  238. return obj.constructor.prototype;
  239. }
  240. function hasProperty(obj, property) {
  241. if (!obj)
  242. return false;
  243. if (Object.prototype.hasOwnProperty.call(obj, property))
  244. return true;
  245. return hasProperty(getPrototype(obj), property);
  246. }
  247. const IS_KEYED_SENTINEL = "@@__IMMUTABLE_KEYED__@@";
  248. const IS_SET_SENTINEL = "@@__IMMUTABLE_SET__@@";
  249. const IS_ORDERED_SENTINEL = "@@__IMMUTABLE_ORDERED__@@";
  250. function isImmutableUnorderedKeyed(maybeKeyed) {
  251. return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL] && !maybeKeyed[IS_ORDERED_SENTINEL]);
  252. }
  253. function isImmutableUnorderedSet(maybeSet) {
  254. return !!(maybeSet && maybeSet[IS_SET_SENTINEL] && !maybeSet[IS_ORDERED_SENTINEL]);
  255. }
  256. const IteratorSymbol = Symbol.iterator;
  257. const hasIterator = (object) => !!(object != null && object[IteratorSymbol]);
  258. const iterableEquality = (a, b, aStack = [], bStack = []) => {
  259. if (typeof a !== "object" || typeof b !== "object" || Array.isArray(a) || Array.isArray(b) || !hasIterator(a) || !hasIterator(b))
  260. return void 0;
  261. if (a.constructor !== b.constructor)
  262. return false;
  263. let length = aStack.length;
  264. while (length--) {
  265. if (aStack[length] === a)
  266. return bStack[length] === b;
  267. }
  268. aStack.push(a);
  269. bStack.push(b);
  270. const iterableEqualityWithStack = (a2, b2) => iterableEquality(a2, b2, [...aStack], [...bStack]);
  271. if (a.size !== void 0) {
  272. if (a.size !== b.size) {
  273. return false;
  274. } else if (isA("Set", a) || isImmutableUnorderedSet(a)) {
  275. let allFound = true;
  276. for (const aValue of a) {
  277. if (!b.has(aValue)) {
  278. let has = false;
  279. for (const bValue of b) {
  280. const isEqual = equals(aValue, bValue, [iterableEqualityWithStack]);
  281. if (isEqual === true)
  282. has = true;
  283. }
  284. if (has === false) {
  285. allFound = false;
  286. break;
  287. }
  288. }
  289. }
  290. aStack.pop();
  291. bStack.pop();
  292. return allFound;
  293. } else if (isA("Map", a) || isImmutableUnorderedKeyed(a)) {
  294. let allFound = true;
  295. for (const aEntry of a) {
  296. if (!b.has(aEntry[0]) || !equals(aEntry[1], b.get(aEntry[0]), [iterableEqualityWithStack])) {
  297. let has = false;
  298. for (const bEntry of b) {
  299. const matchedKey = equals(aEntry[0], bEntry[0], [
  300. iterableEqualityWithStack
  301. ]);
  302. let matchedValue = false;
  303. if (matchedKey === true) {
  304. matchedValue = equals(aEntry[1], bEntry[1], [
  305. iterableEqualityWithStack
  306. ]);
  307. }
  308. if (matchedValue === true)
  309. has = true;
  310. }
  311. if (has === false) {
  312. allFound = false;
  313. break;
  314. }
  315. }
  316. }
  317. aStack.pop();
  318. bStack.pop();
  319. return allFound;
  320. }
  321. }
  322. const bIterator = b[IteratorSymbol]();
  323. for (const aValue of a) {
  324. const nextB = bIterator.next();
  325. if (nextB.done || !equals(aValue, nextB.value, [iterableEqualityWithStack]))
  326. return false;
  327. }
  328. if (!bIterator.next().done)
  329. return false;
  330. aStack.pop();
  331. bStack.pop();
  332. return true;
  333. };
  334. const hasPropertyInObject = (object, key) => {
  335. const shouldTerminate = !object || typeof object !== "object" || object === Object.prototype;
  336. if (shouldTerminate)
  337. return false;
  338. return Object.prototype.hasOwnProperty.call(object, key) || hasPropertyInObject(Object.getPrototypeOf(object), key);
  339. };
  340. const isObjectWithKeys = (a) => isObject(a) && !(a instanceof Error) && !Array.isArray(a) && !(a instanceof Date);
  341. const subsetEquality = (object, subset) => {
  342. const subsetEqualityWithContext = (seenReferences = /* @__PURE__ */ new WeakMap()) => (object2, subset2) => {
  343. if (!isObjectWithKeys(subset2))
  344. return void 0;
  345. return Object.keys(subset2).every((key) => {
  346. if (isObjectWithKeys(subset2[key])) {
  347. if (seenReferences.has(subset2[key]))
  348. return equals(object2[key], subset2[key], [iterableEquality]);
  349. seenReferences.set(subset2[key], true);
  350. }
  351. const result = object2 != null && hasPropertyInObject(object2, key) && equals(object2[key], subset2[key], [
  352. iterableEquality,
  353. subsetEqualityWithContext(seenReferences)
  354. ]);
  355. seenReferences.delete(subset2[key]);
  356. return result;
  357. });
  358. };
  359. return subsetEqualityWithContext()(object, subset);
  360. };
  361. const typeEquality = (a, b) => {
  362. if (a == null || b == null || a.constructor === b.constructor)
  363. return void 0;
  364. return false;
  365. };
  366. const arrayBufferEquality = (a, b) => {
  367. if (!(a instanceof ArrayBuffer) || !(b instanceof ArrayBuffer))
  368. return void 0;
  369. const dataViewA = new DataView(a);
  370. const dataViewB = new DataView(b);
  371. if (dataViewA.byteLength !== dataViewB.byteLength)
  372. return false;
  373. for (let i = 0; i < dataViewA.byteLength; i++) {
  374. if (dataViewA.getUint8(i) !== dataViewB.getUint8(i))
  375. return false;
  376. }
  377. return true;
  378. };
  379. const sparseArrayEquality = (a, b) => {
  380. if (!Array.isArray(a) || !Array.isArray(b))
  381. return void 0;
  382. const aKeys = Object.keys(a);
  383. const bKeys = Object.keys(b);
  384. return equals(a, b, [iterableEquality, typeEquality], true) && equals(aKeys, bKeys);
  385. };
  386. const generateToBeMessage = (deepEqualityName, expected = "#{this}", actual = "#{exp}") => {
  387. const toBeMessage = `expected ${expected} to be ${actual} // Object.is equality`;
  388. if (["toStrictEqual", "toEqual"].includes(deepEqualityName))
  389. return `${toBeMessage}
  390. If it should pass with deep equality, replace "toBe" with "${deepEqualityName}"
  391. Expected: ${expected}
  392. Received: serializes to the same string
  393. `;
  394. return toBeMessage;
  395. };
  396. class AsymmetricMatcher {
  397. constructor(sample, inverse = false) {
  398. this.sample = sample;
  399. this.inverse = inverse;
  400. this.$$typeof = Symbol.for("jest.asymmetricMatcher");
  401. }
  402. getMatcherContext(expect) {
  403. return {
  404. ...getState(expect || globalThis[GLOBAL_EXPECT]),
  405. equals,
  406. isNot: this.inverse,
  407. utils: {
  408. ...getMatcherUtils(),
  409. diff,
  410. stringify,
  411. iterableEquality,
  412. subsetEquality
  413. }
  414. };
  415. }
  416. }
  417. class StringContaining extends AsymmetricMatcher {
  418. constructor(sample, inverse = false) {
  419. if (!isA("String", sample))
  420. throw new Error("Expected is not a string");
  421. super(sample, inverse);
  422. }
  423. asymmetricMatch(other) {
  424. const result = isA("String", other) && other.includes(this.sample);
  425. return this.inverse ? !result : result;
  426. }
  427. toString() {
  428. return `String${this.inverse ? "Not" : ""}Containing`;
  429. }
  430. getExpectedType() {
  431. return "string";
  432. }
  433. }
  434. class Anything extends AsymmetricMatcher {
  435. asymmetricMatch(other) {
  436. return other != null;
  437. }
  438. toString() {
  439. return "Anything";
  440. }
  441. toAsymmetricMatcher() {
  442. return "Anything";
  443. }
  444. }
  445. class ObjectContaining extends AsymmetricMatcher {
  446. constructor(sample, inverse = false) {
  447. super(sample, inverse);
  448. }
  449. getPrototype(obj) {
  450. if (Object.getPrototypeOf)
  451. return Object.getPrototypeOf(obj);
  452. if (obj.constructor.prototype === obj)
  453. return null;
  454. return obj.constructor.prototype;
  455. }
  456. hasProperty(obj, property) {
  457. if (!obj)
  458. return false;
  459. if (Object.prototype.hasOwnProperty.call(obj, property))
  460. return true;
  461. return this.hasProperty(this.getPrototype(obj), property);
  462. }
  463. asymmetricMatch(other) {
  464. if (typeof this.sample !== "object") {
  465. throw new TypeError(
  466. `You must provide an object to ${this.toString()}, not '${typeof this.sample}'.`
  467. );
  468. }
  469. let result = true;
  470. for (const property in this.sample) {
  471. if (!this.hasProperty(other, property) || !equals(this.sample[property], other[property])) {
  472. result = false;
  473. break;
  474. }
  475. }
  476. return this.inverse ? !result : result;
  477. }
  478. toString() {
  479. return `Object${this.inverse ? "Not" : ""}Containing`;
  480. }
  481. getExpectedType() {
  482. return "object";
  483. }
  484. }
  485. class ArrayContaining extends AsymmetricMatcher {
  486. constructor(sample, inverse = false) {
  487. super(sample, inverse);
  488. }
  489. asymmetricMatch(other) {
  490. if (!Array.isArray(this.sample)) {
  491. throw new TypeError(
  492. `You must provide an array to ${this.toString()}, not '${typeof this.sample}'.`
  493. );
  494. }
  495. const result = this.sample.length === 0 || Array.isArray(other) && this.sample.every(
  496. (item) => other.some((another) => equals(item, another))
  497. );
  498. return this.inverse ? !result : result;
  499. }
  500. toString() {
  501. return `Array${this.inverse ? "Not" : ""}Containing`;
  502. }
  503. getExpectedType() {
  504. return "array";
  505. }
  506. }
  507. class Any extends AsymmetricMatcher {
  508. constructor(sample) {
  509. if (typeof sample === "undefined") {
  510. throw new TypeError(
  511. "any() expects to be passed a constructor function. Please pass one or use anything() to match any object."
  512. );
  513. }
  514. super(sample);
  515. }
  516. fnNameFor(func) {
  517. if (func.name)
  518. return func.name;
  519. const functionToString = Function.prototype.toString;
  520. const matches = functionToString.call(func).match(/^(?:async)?\s*function\s*\*?\s*([\w$]+)\s*\(/);
  521. return matches ? matches[1] : "<anonymous>";
  522. }
  523. asymmetricMatch(other) {
  524. if (this.sample === String)
  525. return typeof other == "string" || other instanceof String;
  526. if (this.sample === Number)
  527. return typeof other == "number" || other instanceof Number;
  528. if (this.sample === Function)
  529. return typeof other == "function" || other instanceof Function;
  530. if (this.sample === Boolean)
  531. return typeof other == "boolean" || other instanceof Boolean;
  532. if (this.sample === BigInt)
  533. return typeof other == "bigint" || other instanceof BigInt;
  534. if (this.sample === Symbol)
  535. return typeof other == "symbol" || other instanceof Symbol;
  536. if (this.sample === Object)
  537. return typeof other == "object";
  538. return other instanceof this.sample;
  539. }
  540. toString() {
  541. return "Any";
  542. }
  543. getExpectedType() {
  544. if (this.sample === String)
  545. return "string";
  546. if (this.sample === Number)
  547. return "number";
  548. if (this.sample === Function)
  549. return "function";
  550. if (this.sample === Object)
  551. return "object";
  552. if (this.sample === Boolean)
  553. return "boolean";
  554. return this.fnNameFor(this.sample);
  555. }
  556. toAsymmetricMatcher() {
  557. return `Any<${this.fnNameFor(this.sample)}>`;
  558. }
  559. }
  560. class StringMatching extends AsymmetricMatcher {
  561. constructor(sample, inverse = false) {
  562. if (!isA("String", sample) && !isA("RegExp", sample))
  563. throw new Error("Expected is not a String or a RegExp");
  564. super(new RegExp(sample), inverse);
  565. }
  566. asymmetricMatch(other) {
  567. const result = isA("String", other) && this.sample.test(other);
  568. return this.inverse ? !result : result;
  569. }
  570. toString() {
  571. return `String${this.inverse ? "Not" : ""}Matching`;
  572. }
  573. getExpectedType() {
  574. return "string";
  575. }
  576. }
  577. const JestAsymmetricMatchers = (chai, utils) => {
  578. utils.addMethod(
  579. chai.expect,
  580. "anything",
  581. () => new Anything()
  582. );
  583. utils.addMethod(
  584. chai.expect,
  585. "any",
  586. (expected) => new Any(expected)
  587. );
  588. utils.addMethod(
  589. chai.expect,
  590. "stringContaining",
  591. (expected) => new StringContaining(expected)
  592. );
  593. utils.addMethod(
  594. chai.expect,
  595. "objectContaining",
  596. (expected) => new ObjectContaining(expected)
  597. );
  598. utils.addMethod(
  599. chai.expect,
  600. "arrayContaining",
  601. (expected) => new ArrayContaining(expected)
  602. );
  603. utils.addMethod(
  604. chai.expect,
  605. "stringMatching",
  606. (expected) => new StringMatching(expected)
  607. );
  608. chai.expect.not = {
  609. stringContaining: (expected) => new StringContaining(expected, true),
  610. objectContaining: (expected) => new ObjectContaining(expected, true),
  611. arrayContaining: (expected) => new ArrayContaining(expected, true),
  612. stringMatching: (expected) => new StringMatching(expected, true)
  613. };
  614. };
  615. const JestChaiExpect = (chai, utils) => {
  616. const c = () => getColors();
  617. function def(name, fn) {
  618. const addMethod = (n) => {
  619. utils.addMethod(chai.Assertion.prototype, n, fn);
  620. utils.addMethod(globalThis[JEST_MATCHERS_OBJECT].matchers, n, fn);
  621. };
  622. if (Array.isArray(name))
  623. name.forEach((n) => addMethod(n));
  624. else
  625. addMethod(name);
  626. }
  627. ["throw", "throws", "Throw"].forEach((m) => {
  628. utils.overwriteMethod(chai.Assertion.prototype, m, (_super) => {
  629. return function(...args) {
  630. const promise = utils.flag(this, "promise");
  631. const object = utils.flag(this, "object");
  632. const isNot = utils.flag(this, "negate");
  633. if (promise === "rejects") {
  634. utils.flag(this, "object", () => {
  635. throw object;
  636. });
  637. } else if (promise === "resolves" && typeof object !== "function") {
  638. if (!isNot) {
  639. const message = utils.flag(this, "message") || "expected promise to throw an error, but it didn't";
  640. const error = {
  641. showDiff: false
  642. };
  643. throw new AssertionError(message, error, utils.flag(this, "ssfi"));
  644. } else {
  645. return;
  646. }
  647. }
  648. _super.apply(this, args);
  649. };
  650. });
  651. });
  652. def("withTest", function(test) {
  653. utils.flag(this, "vitest-test", test);
  654. return this;
  655. });
  656. def("toEqual", function(expected) {
  657. const actual = utils.flag(this, "object");
  658. const equal = equals(
  659. actual,
  660. expected,
  661. [iterableEquality]
  662. );
  663. return this.assert(
  664. equal,
  665. "expected #{this} to deeply equal #{exp}",
  666. "expected #{this} to not deeply equal #{exp}",
  667. expected,
  668. actual
  669. );
  670. });
  671. def("toStrictEqual", function(expected) {
  672. const obj = utils.flag(this, "object");
  673. const equal = equals(
  674. obj,
  675. expected,
  676. [
  677. iterableEquality,
  678. typeEquality,
  679. sparseArrayEquality,
  680. arrayBufferEquality
  681. ],
  682. true
  683. );
  684. return this.assert(
  685. equal,
  686. "expected #{this} to strictly equal #{exp}",
  687. "expected #{this} to not strictly equal #{exp}",
  688. expected,
  689. obj
  690. );
  691. });
  692. def("toBe", function(expected) {
  693. const actual = this._obj;
  694. const pass = Object.is(actual, expected);
  695. let deepEqualityName = "";
  696. if (!pass) {
  697. const toStrictEqualPass = equals(
  698. actual,
  699. expected,
  700. [
  701. iterableEquality,
  702. typeEquality,
  703. sparseArrayEquality,
  704. arrayBufferEquality
  705. ],
  706. true
  707. );
  708. if (toStrictEqualPass) {
  709. deepEqualityName = "toStrictEqual";
  710. } else {
  711. const toEqualPass = equals(
  712. actual,
  713. expected,
  714. [iterableEquality]
  715. );
  716. if (toEqualPass)
  717. deepEqualityName = "toEqual";
  718. }
  719. }
  720. return this.assert(
  721. pass,
  722. generateToBeMessage(deepEqualityName),
  723. "expected #{this} not to be #{exp} // Object.is equality",
  724. expected,
  725. actual
  726. );
  727. });
  728. def("toMatchObject", function(expected) {
  729. const actual = this._obj;
  730. return this.assert(
  731. equals(actual, expected, [iterableEquality, subsetEquality]),
  732. "expected #{this} to match object #{exp}",
  733. "expected #{this} to not match object #{exp}",
  734. expected,
  735. actual
  736. );
  737. });
  738. def("toMatch", function(expected) {
  739. if (typeof expected === "string")
  740. return this.include(expected);
  741. else
  742. return this.match(expected);
  743. });
  744. def("toContain", function(item) {
  745. return this.contain(item);
  746. });
  747. def("toContainEqual", function(expected) {
  748. const obj = utils.flag(this, "object");
  749. const index = Array.from(obj).findIndex((item) => {
  750. return equals(item, expected);
  751. });
  752. this.assert(
  753. index !== -1,
  754. "expected #{this} to deep equally contain #{exp}",
  755. "expected #{this} to not deep equally contain #{exp}",
  756. expected
  757. );
  758. });
  759. def("toBeTruthy", function() {
  760. const obj = utils.flag(this, "object");
  761. this.assert(
  762. Boolean(obj),
  763. "expected #{this} to be truthy",
  764. "expected #{this} to not be truthy",
  765. obj
  766. );
  767. });
  768. def("toBeFalsy", function() {
  769. const obj = utils.flag(this, "object");
  770. this.assert(
  771. !obj,
  772. "expected #{this} to be falsy",
  773. "expected #{this} to not be falsy",
  774. obj
  775. );
  776. });
  777. def("toBeGreaterThan", function(expected) {
  778. const actual = this._obj;
  779. assertTypes(actual, "actual", ["number", "bigint"]);
  780. assertTypes(expected, "expected", ["number", "bigint"]);
  781. return this.assert(
  782. actual > expected,
  783. `expected ${actual} to be greater than ${expected}`,
  784. `expected ${actual} to be not greater than ${expected}`,
  785. actual,
  786. expected
  787. );
  788. });
  789. def("toBeGreaterThanOrEqual", function(expected) {
  790. const actual = this._obj;
  791. assertTypes(actual, "actual", ["number", "bigint"]);
  792. assertTypes(expected, "expected", ["number", "bigint"]);
  793. return this.assert(
  794. actual >= expected,
  795. `expected ${actual} to be greater than or equal to ${expected}`,
  796. `expected ${actual} to be not greater than or equal to ${expected}`,
  797. actual,
  798. expected
  799. );
  800. });
  801. def("toBeLessThan", function(expected) {
  802. const actual = this._obj;
  803. assertTypes(actual, "actual", ["number", "bigint"]);
  804. assertTypes(expected, "expected", ["number", "bigint"]);
  805. return this.assert(
  806. actual < expected,
  807. `expected ${actual} to be less than ${expected}`,
  808. `expected ${actual} to be not less than ${expected}`,
  809. actual,
  810. expected
  811. );
  812. });
  813. def("toBeLessThanOrEqual", function(expected) {
  814. const actual = this._obj;
  815. assertTypes(actual, "actual", ["number", "bigint"]);
  816. assertTypes(expected, "expected", ["number", "bigint"]);
  817. return this.assert(
  818. actual <= expected,
  819. `expected ${actual} to be less than or equal to ${expected}`,
  820. `expected ${actual} to be not less than or equal to ${expected}`,
  821. actual,
  822. expected
  823. );
  824. });
  825. def("toBeNaN", function() {
  826. return this.be.NaN;
  827. });
  828. def("toBeUndefined", function() {
  829. return this.be.undefined;
  830. });
  831. def("toBeNull", function() {
  832. return this.be.null;
  833. });
  834. def("toBeDefined", function() {
  835. const negate = utils.flag(this, "negate");
  836. utils.flag(this, "negate", false);
  837. if (negate)
  838. return this.be.undefined;
  839. return this.not.be.undefined;
  840. });
  841. def("toBeTypeOf", function(expected) {
  842. const actual = typeof this._obj;
  843. const equal = expected === actual;
  844. return this.assert(
  845. equal,
  846. "expected #{this} to be type of #{exp}",
  847. "expected #{this} not to be type of #{exp}",
  848. expected,
  849. actual
  850. );
  851. });
  852. def("toBeInstanceOf", function(obj) {
  853. return this.instanceOf(obj);
  854. });
  855. def("toHaveLength", function(length) {
  856. return this.have.length(length);
  857. });
  858. def("toHaveProperty", function(...args) {
  859. if (Array.isArray(args[0]))
  860. args[0] = args[0].map((key) => String(key).replace(/([.[\]])/g, "\\$1")).join(".");
  861. const actual = this._obj;
  862. const [propertyName, expected] = args;
  863. const getValue = () => {
  864. const hasOwn = Object.prototype.hasOwnProperty.call(actual, propertyName);
  865. if (hasOwn)
  866. return { value: actual[propertyName], exists: true };
  867. return utils.getPathInfo(actual, propertyName);
  868. };
  869. const { value, exists } = getValue();
  870. const pass = exists && (args.length === 1 || equals(expected, value));
  871. const valueString = args.length === 1 ? "" : ` with value ${utils.objDisplay(expected)}`;
  872. return this.assert(
  873. pass,
  874. `expected #{this} to have property "${propertyName}"${valueString}`,
  875. `expected #{this} to not have property "${propertyName}"${valueString}`,
  876. actual
  877. );
  878. });
  879. def("toBeCloseTo", function(received, precision = 2) {
  880. const expected = this._obj;
  881. let pass = false;
  882. let expectedDiff = 0;
  883. let receivedDiff = 0;
  884. if (received === Infinity && expected === Infinity) {
  885. pass = true;
  886. } else if (received === -Infinity && expected === -Infinity) {
  887. pass = true;
  888. } else {
  889. expectedDiff = 10 ** -precision / 2;
  890. receivedDiff = Math.abs(expected - received);
  891. pass = receivedDiff < expectedDiff;
  892. }
  893. return this.assert(
  894. pass,
  895. `expected #{this} to be close to #{exp}, received difference is ${receivedDiff}, but expected ${expectedDiff}`,
  896. `expected #{this} to not be close to #{exp}, received difference is ${receivedDiff}, but expected ${expectedDiff}`,
  897. received,
  898. expected
  899. );
  900. });
  901. const assertIsMock = (assertion) => {
  902. if (!isMockFunction(assertion._obj))
  903. throw new TypeError(`${utils.inspect(assertion._obj)} is not a spy or a call to a spy!`);
  904. };
  905. const getSpy = (assertion) => {
  906. assertIsMock(assertion);
  907. return assertion._obj;
  908. };
  909. const ordinalOf = (i) => {
  910. const j = i % 10;
  911. const k = i % 100;
  912. if (j === 1 && k !== 11)
  913. return `${i}st`;
  914. if (j === 2 && k !== 12)
  915. return `${i}nd`;
  916. if (j === 3 && k !== 13)
  917. return `${i}rd`;
  918. return `${i}th`;
  919. };
  920. const formatCalls = (spy, msg, actualCall) => {
  921. msg += c().gray(`
  922. Received:
  923. ${spy.mock.calls.map((callArg, i) => {
  924. let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call:
  925. `);
  926. if (actualCall)
  927. methodCall += diff(callArg, actualCall, { showLegend: false });
  928. else
  929. methodCall += stringify(callArg).split("\n").map((line) => ` ${line}`).join("\n");
  930. methodCall += "\n";
  931. return methodCall;
  932. }).join("\n")}`);
  933. msg += c().gray(`
  934. Number of calls: ${c().bold(spy.mock.calls.length)}
  935. `);
  936. return msg;
  937. };
  938. const formatReturns = (spy, msg, actualReturn) => {
  939. msg += c().gray(`
  940. Received:
  941. ${spy.mock.results.map((callReturn, i) => {
  942. let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call return:
  943. `);
  944. if (actualReturn)
  945. methodCall += diff(callReturn.value, actualReturn, { showLegend: false });
  946. else
  947. methodCall += stringify(callReturn).split("\n").map((line) => ` ${line}`).join("\n");
  948. methodCall += "\n";
  949. return methodCall;
  950. }).join("\n")}`);
  951. msg += c().gray(`
  952. Number of calls: ${c().bold(spy.mock.calls.length)}
  953. `);
  954. return msg;
  955. };
  956. def(["toHaveBeenCalledTimes", "toBeCalledTimes"], function(number) {
  957. const spy = getSpy(this);
  958. const spyName = spy.getMockName();
  959. const callCount = spy.mock.calls.length;
  960. return this.assert(
  961. callCount === number,
  962. `expected "${spyName}" to be called #{exp} times`,
  963. `expected "${spyName}" to not be called #{exp} times`,
  964. number,
  965. callCount
  966. );
  967. });
  968. def("toHaveBeenCalledOnce", function() {
  969. const spy = getSpy(this);
  970. const spyName = spy.getMockName();
  971. const callCount = spy.mock.calls.length;
  972. return this.assert(
  973. callCount === 1,
  974. `expected "${spyName}" to be called once`,
  975. `expected "${spyName}" to not be called once`,
  976. 1,
  977. callCount
  978. );
  979. });
  980. def(["toHaveBeenCalled", "toBeCalled"], function() {
  981. const spy = getSpy(this);
  982. const spyName = spy.getMockName();
  983. const called = spy.mock.calls.length > 0;
  984. const isNot = utils.flag(this, "negate");
  985. let msg = utils.getMessage(
  986. this,
  987. [
  988. called,
  989. `expected "${spyName}" to be called at least once`,
  990. `expected "${spyName}" to not be called at all`,
  991. true,
  992. called
  993. ]
  994. );
  995. if (called && isNot)
  996. msg = formatCalls(spy, msg);
  997. if (called && isNot || !called && !isNot) {
  998. const err = new Error(msg);
  999. err.name = "AssertionError";
  1000. throw err;
  1001. }
  1002. });
  1003. def(["toHaveBeenCalledWith", "toBeCalledWith"], function(...args) {
  1004. const spy = getSpy(this);
  1005. const spyName = spy.getMockName();
  1006. const pass = spy.mock.calls.some((callArg) => equals(callArg, args, [iterableEquality]));
  1007. const isNot = utils.flag(this, "negate");
  1008. let msg = utils.getMessage(
  1009. this,
  1010. [
  1011. pass,
  1012. `expected "${spyName}" to be called with arguments: #{exp}`,
  1013. `expected "${spyName}" to not be called with arguments: #{exp}`,
  1014. args
  1015. ]
  1016. );
  1017. if (pass && isNot || !pass && !isNot) {
  1018. msg = formatCalls(spy, msg, args);
  1019. const err = new Error(msg);
  1020. err.name = "AssertionError";
  1021. throw err;
  1022. }
  1023. });
  1024. def(["toHaveBeenNthCalledWith", "nthCalledWith"], function(times, ...args) {
  1025. const spy = getSpy(this);
  1026. const spyName = spy.getMockName();
  1027. const nthCall = spy.mock.calls[times - 1];
  1028. this.assert(
  1029. equals(nthCall, args, [iterableEquality]),
  1030. `expected ${ordinalOf(times)} "${spyName}" call to have been called with #{exp}`,
  1031. `expected ${ordinalOf(times)} "${spyName}" call to not have been called with #{exp}`,
  1032. args,
  1033. nthCall
  1034. );
  1035. });
  1036. def(["toHaveBeenLastCalledWith", "lastCalledWith"], function(...args) {
  1037. const spy = getSpy(this);
  1038. const spyName = spy.getMockName();
  1039. const lastCall = spy.mock.calls[spy.calls.length - 1];
  1040. this.assert(
  1041. equals(lastCall, args, [iterableEquality]),
  1042. `expected last "${spyName}" call to have been called with #{exp}`,
  1043. `expected last "${spyName}" call to not have been called with #{exp}`,
  1044. args,
  1045. lastCall
  1046. );
  1047. });
  1048. def(["toThrow", "toThrowError"], function(expected) {
  1049. if (typeof expected === "string" || typeof expected === "undefined" || expected instanceof RegExp)
  1050. return this.throws(expected);
  1051. const obj = this._obj;
  1052. const promise = utils.flag(this, "promise");
  1053. const isNot = utils.flag(this, "negate");
  1054. let thrown = null;
  1055. if (promise === "rejects") {
  1056. thrown = obj;
  1057. } else if (promise === "resolves" && typeof obj !== "function") {
  1058. if (!isNot) {
  1059. const message = utils.flag(this, "message") || "expected promise to throw an error, but it didn't";
  1060. const error = {
  1061. showDiff: false
  1062. };
  1063. throw new AssertionError(message, error, utils.flag(this, "ssfi"));
  1064. } else {
  1065. return;
  1066. }
  1067. } else {
  1068. try {
  1069. obj();
  1070. } catch (err) {
  1071. thrown = err;
  1072. }
  1073. }
  1074. if (typeof expected === "function") {
  1075. const name = expected.name || expected.prototype.constructor.name;
  1076. return this.assert(
  1077. thrown && thrown instanceof expected,
  1078. `expected error to be instance of ${name}`,
  1079. `expected error not to be instance of ${name}`,
  1080. expected,
  1081. thrown
  1082. );
  1083. }
  1084. if (expected instanceof Error) {
  1085. return this.assert(
  1086. thrown && expected.message === thrown.message,
  1087. `expected error to have message: ${expected.message}`,
  1088. `expected error not to have message: ${expected.message}`,
  1089. expected.message,
  1090. thrown && thrown.message
  1091. );
  1092. }
  1093. if (typeof expected === "object" && "asymmetricMatch" in expected && typeof expected.asymmetricMatch === "function") {
  1094. const matcher = expected;
  1095. return this.assert(
  1096. thrown && matcher.asymmetricMatch(thrown),
  1097. "expected error to match asymmetric matcher",
  1098. "expected error not to match asymmetric matcher",
  1099. matcher.toString(),
  1100. thrown
  1101. );
  1102. }
  1103. throw new Error(`"toThrow" expects string, RegExp, function, Error instance or asymmetric matcher, got "${typeof expected}"`);
  1104. });
  1105. def(["toHaveReturned", "toReturn"], function() {
  1106. const spy = getSpy(this);
  1107. const spyName = spy.getMockName();
  1108. const calledAndNotThrew = spy.mock.calls.length > 0 && spy.mock.results.some(({ type }) => type !== "throw");
  1109. this.assert(
  1110. calledAndNotThrew,
  1111. `expected "${spyName}" to be successfully called at least once`,
  1112. `expected "${spyName}" to not be successfully called`,
  1113. calledAndNotThrew,
  1114. !calledAndNotThrew
  1115. );
  1116. });
  1117. def(["toHaveReturnedTimes", "toReturnTimes"], function(times) {
  1118. const spy = getSpy(this);
  1119. const spyName = spy.getMockName();
  1120. const successfulReturns = spy.mock.results.reduce((success, { type }) => type === "throw" ? success : ++success, 0);
  1121. this.assert(
  1122. successfulReturns === times,
  1123. `expected "${spyName}" to be successfully called ${times} times`,
  1124. `expected "${spyName}" to not be successfully called ${times} times`,
  1125. `expected number of returns: ${times}`,
  1126. `received number of returns: ${successfulReturns}`
  1127. );
  1128. });
  1129. def(["toHaveReturnedWith", "toReturnWith"], function(value) {
  1130. const spy = getSpy(this);
  1131. const spyName = spy.getMockName();
  1132. const pass = spy.mock.results.some(({ type, value: result }) => type === "return" && equals(value, result));
  1133. const isNot = utils.flag(this, "negate");
  1134. let msg = utils.getMessage(
  1135. this,
  1136. [
  1137. pass,
  1138. `expected "${spyName}" to return with: #{exp} at least once`,
  1139. `expected "${spyName}" to not return with: #{exp}`,
  1140. value
  1141. ]
  1142. );
  1143. if (pass && isNot || !pass && !isNot) {
  1144. msg = formatReturns(spy, msg, value);
  1145. const err = new Error(msg);
  1146. err.name = "AssertionError";
  1147. throw err;
  1148. }
  1149. });
  1150. def(["toHaveLastReturnedWith", "lastReturnedWith"], function(value) {
  1151. const spy = getSpy(this);
  1152. const spyName = spy.getMockName();
  1153. const { value: lastResult } = spy.mock.results[spy.returns.length - 1];
  1154. const pass = equals(lastResult, value);
  1155. this.assert(
  1156. pass,
  1157. `expected last "${spyName}" call to return #{exp}`,
  1158. `expected last "${spyName}" call to not return #{exp}`,
  1159. value,
  1160. lastResult
  1161. );
  1162. });
  1163. def(["toHaveNthReturnedWith", "nthReturnedWith"], function(nthCall, value) {
  1164. const spy = getSpy(this);
  1165. const spyName = spy.getMockName();
  1166. const isNot = utils.flag(this, "negate");
  1167. const { type: callType, value: callResult } = spy.mock.results[nthCall - 1];
  1168. const ordinalCall = `${ordinalOf(nthCall)} call`;
  1169. if (!isNot && callType === "throw")
  1170. chai.assert.fail(`expected ${ordinalCall} to return #{exp}, but instead it threw an error`);
  1171. const nthCallReturn = equals(callResult, value);
  1172. this.assert(
  1173. nthCallReturn,
  1174. `expected ${ordinalCall} "${spyName}" call to return #{exp}`,
  1175. `expected ${ordinalCall} "${spyName}" call to not return #{exp}`,
  1176. value,
  1177. callResult
  1178. );
  1179. });
  1180. def("toSatisfy", function(matcher, message) {
  1181. return this.be.satisfy(matcher, message);
  1182. });
  1183. utils.addProperty(chai.Assertion.prototype, "resolves", function __VITEST_RESOLVES__() {
  1184. utils.flag(this, "promise", "resolves");
  1185. utils.flag(this, "error", new Error("resolves"));
  1186. const obj = utils.flag(this, "object");
  1187. if (typeof (obj == null ? void 0 : obj.then) !== "function")
  1188. throw new TypeError(`You must provide a Promise to expect() when using .resolves, not '${typeof obj}'.`);
  1189. const proxy = new Proxy(this, {
  1190. get: (target, key, receiver) => {
  1191. const result = Reflect.get(target, key, receiver);
  1192. if (typeof result !== "function")
  1193. return result instanceof chai.Assertion ? proxy : result;
  1194. return async (...args) => {
  1195. return obj.then(
  1196. (value) => {
  1197. utils.flag(this, "object", value);
  1198. return result.call(this, ...args);
  1199. },
  1200. (err) => {
  1201. throw new Error(`promise rejected "${String(err)}" instead of resolving`);
  1202. }
  1203. );
  1204. };
  1205. }
  1206. });
  1207. return proxy;
  1208. });
  1209. utils.addProperty(chai.Assertion.prototype, "rejects", function __VITEST_REJECTS__() {
  1210. utils.flag(this, "promise", "rejects");
  1211. utils.flag(this, "error", new Error("rejects"));
  1212. const obj = utils.flag(this, "object");
  1213. const wrapper = typeof obj === "function" ? obj() : obj;
  1214. if (typeof (wrapper == null ? void 0 : wrapper.then) !== "function")
  1215. throw new TypeError(`You must provide a Promise to expect() when using .rejects, not '${typeof wrapper}'.`);
  1216. const proxy = new Proxy(this, {
  1217. get: (target, key, receiver) => {
  1218. const result = Reflect.get(target, key, receiver);
  1219. if (typeof result !== "function")
  1220. return result instanceof chai.Assertion ? proxy : result;
  1221. return async (...args) => {
  1222. return wrapper.then(
  1223. (value) => {
  1224. throw new Error(`promise resolved "${String(value)}" instead of rejecting`);
  1225. },
  1226. (err) => {
  1227. utils.flag(this, "object", err);
  1228. return result.call(this, ...args);
  1229. }
  1230. );
  1231. };
  1232. }
  1233. });
  1234. return proxy;
  1235. });
  1236. };
  1237. const getMatcherState = (assertion, expect) => {
  1238. const obj = assertion._obj;
  1239. const isNot = util.flag(assertion, "negate");
  1240. const promise = util.flag(assertion, "promise") || "";
  1241. const jestUtils = {
  1242. ...getMatcherUtils(),
  1243. diff,
  1244. stringify,
  1245. iterableEquality,
  1246. subsetEquality
  1247. };
  1248. const matcherState = {
  1249. ...getState(expect),
  1250. isNot,
  1251. utils: jestUtils,
  1252. promise,
  1253. equals,
  1254. suppressedErrors: []
  1255. };
  1256. return {
  1257. state: matcherState,
  1258. isNot,
  1259. obj
  1260. };
  1261. };
  1262. class JestExtendError extends Error {
  1263. constructor(message, actual, expected) {
  1264. super(message);
  1265. this.actual = actual;
  1266. this.expected = expected;
  1267. }
  1268. }
  1269. function JestExtendPlugin(expect, matchers) {
  1270. return (c, utils) => {
  1271. Object.entries(matchers).forEach(([expectAssertionName, expectAssertion]) => {
  1272. function expectWrapper(...args) {
  1273. const { state, isNot, obj } = getMatcherState(this, expect);
  1274. const result = expectAssertion.call(state, obj, ...args);
  1275. if (result && typeof result === "object" && result instanceof Promise) {
  1276. return result.then(({ pass: pass2, message: message2, actual: actual2, expected: expected2 }) => {
  1277. if (pass2 && isNot || !pass2 && !isNot)
  1278. throw new JestExtendError(message2(), actual2, expected2);
  1279. });
  1280. }
  1281. const { pass, message, actual, expected } = result;
  1282. if (pass && isNot || !pass && !isNot)
  1283. throw new JestExtendError(message(), actual, expected);
  1284. }
  1285. utils.addMethod(globalThis[JEST_MATCHERS_OBJECT].matchers, expectAssertionName, expectWrapper);
  1286. utils.addMethod(c.Assertion.prototype, expectAssertionName, expectWrapper);
  1287. class CustomMatcher extends AsymmetricMatcher {
  1288. constructor(inverse = false, ...sample) {
  1289. super(sample, inverse);
  1290. }
  1291. asymmetricMatch(other) {
  1292. const { pass } = expectAssertion.call(
  1293. this.getMatcherContext(expect),
  1294. other,
  1295. ...this.sample
  1296. );
  1297. return this.inverse ? !pass : pass;
  1298. }
  1299. toString() {
  1300. return `${this.inverse ? "not." : ""}${expectAssertionName}`;
  1301. }
  1302. getExpectedType() {
  1303. return "any";
  1304. }
  1305. toAsymmetricMatcher() {
  1306. return `${this.toString()}<${this.sample.map(String).join(", ")}>`;
  1307. }
  1308. }
  1309. Object.defineProperty(expect, expectAssertionName, {
  1310. configurable: true,
  1311. enumerable: true,
  1312. value: (...sample) => new CustomMatcher(false, ...sample),
  1313. writable: true
  1314. });
  1315. Object.defineProperty(expect.not, expectAssertionName, {
  1316. configurable: true,
  1317. enumerable: true,
  1318. value: (...sample) => new CustomMatcher(true, ...sample),
  1319. writable: true
  1320. });
  1321. });
  1322. };
  1323. }
  1324. const JestExtend = (chai, utils) => {
  1325. utils.addMethod(chai.expect, "extend", (expect, expects) => {
  1326. chai.use(JestExtendPlugin(expect, expects));
  1327. });
  1328. };
  1329. export { Any, Anything, ArrayContaining, AsymmetricMatcher, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, ObjectContaining, StringContaining, StringMatching, arrayBufferEquality, equals, fnNameFor, generateToBeMessage, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, iterableEquality, setState, sparseArrayEquality, subsetEquality, typeEquality };