@vitest/expect 1.5.3 → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +31 -8
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ export { setupColors } from '@vitest/utils';
3
3
  import { diff } from '@vitest/utils/diff';
4
4
  import { isMockFunction } from '@vitest/spy';
5
5
  import { processError } from '@vitest/utils/error';
6
- import { util } from 'chai';
6
+ import { use, util } from 'chai';
7
7
 
8
8
  const MATCHERS_OBJECT = Symbol.for("matchers-object");
9
9
  const JEST_MATCHERS_OBJECT = Symbol.for("$$jest-matchers-object");
@@ -273,13 +273,34 @@ function hasProperty(obj, property) {
273
273
  }
274
274
  const IS_KEYED_SENTINEL = "@@__IMMUTABLE_KEYED__@@";
275
275
  const IS_SET_SENTINEL = "@@__IMMUTABLE_SET__@@";
276
+ const IS_LIST_SENTINEL = "@@__IMMUTABLE_LIST__@@";
276
277
  const IS_ORDERED_SENTINEL = "@@__IMMUTABLE_ORDERED__@@";
278
+ const IS_RECORD_SYMBOL = "@@__IMMUTABLE_RECORD__@@";
277
279
  function isImmutableUnorderedKeyed(maybeKeyed) {
278
280
  return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL] && !maybeKeyed[IS_ORDERED_SENTINEL]);
279
281
  }
280
282
  function isImmutableUnorderedSet(maybeSet) {
281
283
  return !!(maybeSet && maybeSet[IS_SET_SENTINEL] && !maybeSet[IS_ORDERED_SENTINEL]);
282
284
  }
285
+ function isObjectLiteral(source) {
286
+ return source != null && typeof source === "object" && !Array.isArray(source);
287
+ }
288
+ function isImmutableList(source) {
289
+ return Boolean(source && isObjectLiteral(source) && source[IS_LIST_SENTINEL]);
290
+ }
291
+ function isImmutableOrderedKeyed(source) {
292
+ return Boolean(
293
+ source && isObjectLiteral(source) && source[IS_KEYED_SENTINEL] && source[IS_ORDERED_SENTINEL]
294
+ );
295
+ }
296
+ function isImmutableOrderedSet(source) {
297
+ return Boolean(
298
+ source && isObjectLiteral(source) && source[IS_SET_SENTINEL] && source[IS_ORDERED_SENTINEL]
299
+ );
300
+ }
301
+ function isImmutableRecord(source) {
302
+ return Boolean(source && isObjectLiteral(source) && source[IS_RECORD_SYMBOL]);
303
+ }
283
304
  const IteratorSymbol = Symbol.iterator;
284
305
  function hasIterator(object) {
285
306
  return !!(object != null && object[IteratorSymbol]);
@@ -363,10 +384,12 @@ function iterableEquality(a, b, customTesters = [], aStack = [], bStack = []) {
363
384
  }
364
385
  if (!bIterator.next().done)
365
386
  return false;
366
- const aEntries = Object.entries(a);
367
- const bEntries = Object.entries(b);
368
- if (!equals(aEntries, bEntries))
369
- return false;
387
+ if (!isImmutableList(a) && !isImmutableOrderedKeyed(a) && !isImmutableOrderedSet(a) && !isImmutableRecord(a)) {
388
+ const aEntries = Object.entries(a);
389
+ const bEntries = Object.entries(b);
390
+ if (!equals(aEntries, bEntries))
391
+ return false;
392
+ }
370
393
  aStack.pop();
371
394
  bStack.pop();
372
395
  return true;
@@ -1567,8 +1590,8 @@ class JestExtendError extends Error {
1567
1590
  this.expected = expected;
1568
1591
  }
1569
1592
  }
1570
- function JestExtendPlugin(expect, matchers) {
1571
- return (c, utils) => {
1593
+ function JestExtendPlugin(c, expect, matchers) {
1594
+ return (_, utils) => {
1572
1595
  Object.entries(matchers).forEach(([expectAssertionName, expectAssertion]) => {
1573
1596
  function expectWrapper(...args) {
1574
1597
  const { state, isNot, obj } = getMatcherState(this, expect);
@@ -1632,7 +1655,7 @@ function JestExtendPlugin(expect, matchers) {
1632
1655
  }
1633
1656
  const JestExtend = (chai, utils) => {
1634
1657
  utils.addMethod(chai.expect, "extend", (expect, expects) => {
1635
- chai.use(JestExtendPlugin(expect, expects));
1658
+ use(JestExtendPlugin(chai, expect, expects));
1636
1659
  });
1637
1660
  };
1638
1661
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/expect",
3
3
  "type": "module",
4
- "version": "1.5.3",
4
+ "version": "2.0.0-beta.1",
5
5
  "description": "Jest's expect matchers as a Chai plugin",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -30,15 +30,15 @@
30
30
  "dist"
31
31
  ],
32
32
  "dependencies": {
33
- "chai": "^4.3.10",
34
- "@vitest/spy": "1.5.3",
35
- "@vitest/utils": "1.5.3"
33
+ "chai": "^5.1.1",
34
+ "@vitest/spy": "2.0.0-beta.1",
35
+ "@vitest/utils": "2.0.0-beta.1"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/chai": "4.3.6",
39
39
  "picocolors": "^1.0.0",
40
40
  "rollup-plugin-copy": "^3.5.0",
41
- "@vitest/runner": "1.5.3"
41
+ "@vitest/runner": "2.0.0-beta.1"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "rimraf dist && rollup -c",