@vitest/expect 2.1.3 → 2.1.4
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.
- package/README.md +1 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.js +36 -35
- package/package.json +5 -5
package/README.md
CHANGED
@@ -5,12 +5,12 @@ Jest's expect matchers as a Chai plugin.
|
|
5
5
|
## Usage
|
6
6
|
|
7
7
|
```js
|
8
|
-
import * as chai from 'chai'
|
9
8
|
import {
|
10
9
|
JestAsymmetricMatchers,
|
11
10
|
JestChaiExpect,
|
12
11
|
JestExtend,
|
13
12
|
} from '@vitest/expect'
|
13
|
+
import * as chai from 'chai'
|
14
14
|
|
15
15
|
// allows using expect.extend instead of chai.use to extend plugins
|
16
16
|
chai.use(JestExtend)
|
package/dist/index.d.ts
CHANGED
@@ -1,9 +1,14 @@
|
|
1
|
+
import { stringify, Constructable } from '@vitest/utils';
|
1
2
|
import * as tinyrainbow from 'tinyrainbow';
|
2
3
|
import { Formatter } from 'tinyrainbow';
|
3
|
-
import { stringify, Constructable } from '@vitest/utils';
|
4
4
|
import { diff, printDiffOrStringify } from '@vitest/utils/diff';
|
5
5
|
export { DiffOptions } from '@vitest/utils/diff';
|
6
6
|
|
7
|
+
declare const MATCHERS_OBJECT: unique symbol;
|
8
|
+
declare const JEST_MATCHERS_OBJECT: unique symbol;
|
9
|
+
declare const GLOBAL_EXPECT: unique symbol;
|
10
|
+
declare const ASYMMETRIC_MATCHERS_OBJECT: unique symbol;
|
11
|
+
|
7
12
|
declare function matcherHint(matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions): string;
|
8
13
|
declare function printReceived(object: unknown): string;
|
9
14
|
declare function printExpected(value: unknown): string;
|
@@ -227,6 +232,10 @@ declare class StringMatching extends AsymmetricMatcher<RegExp> {
|
|
227
232
|
}
|
228
233
|
declare const JestAsymmetricMatchers: ChaiPlugin;
|
229
234
|
|
235
|
+
declare const JestChaiExpect: ChaiPlugin;
|
236
|
+
|
237
|
+
declare const JestExtend: ChaiPlugin;
|
238
|
+
|
230
239
|
declare function equals(a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean): boolean;
|
231
240
|
declare function isAsymmetric(obj: any): boolean;
|
232
241
|
declare function hasAsymmetric(obj: any, seen?: Set<unknown>): boolean;
|
@@ -248,16 +257,7 @@ declare function getObjectSubset(object: any, subset: any, customTesters: Array<
|
|
248
257
|
stripped: number;
|
249
258
|
};
|
250
259
|
|
251
|
-
declare const MATCHERS_OBJECT: unique symbol;
|
252
|
-
declare const JEST_MATCHERS_OBJECT: unique symbol;
|
253
|
-
declare const GLOBAL_EXPECT: unique symbol;
|
254
|
-
declare const ASYMMETRIC_MATCHERS_OBJECT: unique symbol;
|
255
|
-
|
256
260
|
declare function getState<State extends MatcherState = MatcherState>(expect: ExpectStatic): State;
|
257
261
|
declare function setState<State extends MatcherState = MatcherState>(state: Partial<State>, expect: ExpectStatic): void;
|
258
262
|
|
259
|
-
declare const JestChaiExpect: ChaiPlugin;
|
260
|
-
|
261
|
-
declare const JestExtend: ChaiPlugin;
|
262
|
-
|
263
263
|
export { ASYMMETRIC_MATCHERS_OBJECT, Any, Anything, ArrayContaining, type Assertion, AsymmetricMatcher, type AsymmetricMatcherInterface, type AsymmetricMatchersContaining, type AsyncExpectationResult, type ChaiPlugin, type ExpectStatic, type ExpectationResult, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, type JestAssertion, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, type MatcherHintOptions, type MatcherState, type MatchersObject, ObjectContaining, type PromisifyAssertion, type RawMatcherFn, StringContaining, StringMatching, type SyncExpectationResult, type Tester, type TesterContext, addCustomEqualityTesters, arrayBufferEquality, equals, fnNameFor, generateToBeMessage, getObjectKeys, getObjectSubset, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, iterableEquality, pluralize, setState, sparseArrayEquality, subsetEquality, typeEquality };
|
package/dist/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { getType, stringify, isObject, assertTypes } from '@vitest/utils';
|
2
|
-
import c from 'tinyrainbow';
|
3
2
|
import { diff, printDiffOrStringify } from '@vitest/utils/diff';
|
3
|
+
import c from 'tinyrainbow';
|
4
4
|
import { isMockFunction } from '@vitest/spy';
|
5
5
|
import { processError } from '@vitest/utils/error';
|
6
6
|
import { use, util } from 'chai';
|
@@ -12,39 +12,6 @@ const ASYMMETRIC_MATCHERS_OBJECT = Symbol.for(
|
|
12
12
|
"asymmetric-matchers-object"
|
13
13
|
);
|
14
14
|
|
15
|
-
if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) {
|
16
|
-
const globalState = /* @__PURE__ */ new WeakMap();
|
17
|
-
const matchers = /* @__PURE__ */ Object.create(null);
|
18
|
-
const customEqualityTesters = [];
|
19
|
-
const assymetricMatchers = /* @__PURE__ */ Object.create(null);
|
20
|
-
Object.defineProperty(globalThis, MATCHERS_OBJECT, {
|
21
|
-
get: () => globalState
|
22
|
-
});
|
23
|
-
Object.defineProperty(globalThis, JEST_MATCHERS_OBJECT, {
|
24
|
-
configurable: true,
|
25
|
-
get: () => ({
|
26
|
-
state: globalState.get(globalThis[GLOBAL_EXPECT]),
|
27
|
-
matchers,
|
28
|
-
customEqualityTesters
|
29
|
-
})
|
30
|
-
});
|
31
|
-
Object.defineProperty(globalThis, ASYMMETRIC_MATCHERS_OBJECT, {
|
32
|
-
get: () => assymetricMatchers
|
33
|
-
});
|
34
|
-
}
|
35
|
-
function getState(expect) {
|
36
|
-
return globalThis[MATCHERS_OBJECT].get(expect);
|
37
|
-
}
|
38
|
-
function setState(state, expect) {
|
39
|
-
const map = globalThis[MATCHERS_OBJECT];
|
40
|
-
const current = map.get(expect) || {};
|
41
|
-
const results = Object.defineProperties(current, {
|
42
|
-
...Object.getOwnPropertyDescriptors(current),
|
43
|
-
...Object.getOwnPropertyDescriptors(state)
|
44
|
-
});
|
45
|
-
map.set(expect, results);
|
46
|
-
}
|
47
|
-
|
48
15
|
const EXPECTED_COLOR = c.green;
|
49
16
|
const RECEIVED_COLOR = c.red;
|
50
17
|
const INVERTED_COLOR = c.inverse;
|
@@ -229,6 +196,7 @@ function eq(a, b, aStack, bStack, customTesters, hasKey2) {
|
|
229
196
|
const numB = +b;
|
230
197
|
return numA === numB || Number.isNaN(numA) && Number.isNaN(numB);
|
231
198
|
}
|
199
|
+
// RegExps are compared by their source patterns and flags.
|
232
200
|
case "[object RegExp]":
|
233
201
|
return a.source === b.source && a.flags === b.flags;
|
234
202
|
}
|
@@ -610,6 +578,39 @@ function getObjectSubset(object, subset, customTesters) {
|
|
610
578
|
return { subset: getObjectSubsetWithContext()(object, subset), stripped };
|
611
579
|
}
|
612
580
|
|
581
|
+
if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) {
|
582
|
+
const globalState = /* @__PURE__ */ new WeakMap();
|
583
|
+
const matchers = /* @__PURE__ */ Object.create(null);
|
584
|
+
const customEqualityTesters = [];
|
585
|
+
const assymetricMatchers = /* @__PURE__ */ Object.create(null);
|
586
|
+
Object.defineProperty(globalThis, MATCHERS_OBJECT, {
|
587
|
+
get: () => globalState
|
588
|
+
});
|
589
|
+
Object.defineProperty(globalThis, JEST_MATCHERS_OBJECT, {
|
590
|
+
configurable: true,
|
591
|
+
get: () => ({
|
592
|
+
state: globalState.get(globalThis[GLOBAL_EXPECT]),
|
593
|
+
matchers,
|
594
|
+
customEqualityTesters
|
595
|
+
})
|
596
|
+
});
|
597
|
+
Object.defineProperty(globalThis, ASYMMETRIC_MATCHERS_OBJECT, {
|
598
|
+
get: () => assymetricMatchers
|
599
|
+
});
|
600
|
+
}
|
601
|
+
function getState(expect) {
|
602
|
+
return globalThis[MATCHERS_OBJECT].get(expect);
|
603
|
+
}
|
604
|
+
function setState(state, expect) {
|
605
|
+
const map = globalThis[MATCHERS_OBJECT];
|
606
|
+
const current = map.get(expect) || {};
|
607
|
+
const results = Object.defineProperties(current, {
|
608
|
+
...Object.getOwnPropertyDescriptors(current),
|
609
|
+
...Object.getOwnPropertyDescriptors(state)
|
610
|
+
});
|
611
|
+
map.set(expect, results);
|
612
|
+
}
|
613
|
+
|
613
614
|
class AsymmetricMatcher {
|
614
615
|
constructor(sample, inverse = false) {
|
615
616
|
this.sample = sample;
|
@@ -1464,7 +1465,7 @@ const JestChaiExpect = (chai, utils) => {
|
|
1464
1465
|
["toThrow", "toThrowError"],
|
1465
1466
|
function(expected) {
|
1466
1467
|
if (typeof expected === "string" || typeof expected === "undefined" || expected instanceof RegExp) {
|
1467
|
-
return this.throws(expected);
|
1468
|
+
return this.throws(expected === "" ? /^$/ : expected);
|
1468
1469
|
}
|
1469
1470
|
const obj = this._obj;
|
1470
1471
|
const promise = utils.flag(this, "promise");
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/expect",
|
3
3
|
"type": "module",
|
4
|
-
"version": "2.1.
|
4
|
+
"version": "2.1.4",
|
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": "^5.1.
|
33
|
+
"chai": "^5.1.2",
|
34
34
|
"tinyrainbow": "^1.2.0",
|
35
|
-
"@vitest/spy": "2.1.
|
36
|
-
"@vitest/utils": "2.1.
|
35
|
+
"@vitest/spy": "2.1.4",
|
36
|
+
"@vitest/utils": "2.1.4"
|
37
37
|
},
|
38
38
|
"devDependencies": {
|
39
39
|
"@types/chai": "4.3.6",
|
40
40
|
"rollup-plugin-copy": "^3.5.0",
|
41
|
-
"@vitest/runner": "2.1.
|
41
|
+
"@vitest/runner": "2.1.4"
|
42
42
|
},
|
43
43
|
"scripts": {
|
44
44
|
"build": "rimraf dist && rollup -c",
|