@vitest/expect 1.0.0-beta.3 → 1.0.0-beta.5
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/dist/index.d.ts +3 -1
- package/dist/index.js +45 -3
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
@@ -58,6 +58,7 @@ interface MatcherHintOptions {
|
|
58
58
|
secondArgumentColor?: Formatter;
|
59
59
|
}
|
60
60
|
interface MatcherState {
|
61
|
+
customTesters: Array<Tester>;
|
61
62
|
assertionCalls: number;
|
62
63
|
currentTestName?: string;
|
63
64
|
dontThrow?: () => void;
|
@@ -254,6 +255,7 @@ declare function pluralize(word: string, count: number): string;
|
|
254
255
|
declare const MATCHERS_OBJECT: unique symbol;
|
255
256
|
declare const JEST_MATCHERS_OBJECT: unique symbol;
|
256
257
|
declare const GLOBAL_EXPECT: unique symbol;
|
258
|
+
declare const ASYMMETRIC_MATCHERS_OBJECT: unique symbol;
|
257
259
|
|
258
260
|
declare function getState<State extends MatcherState = MatcherState>(expect: ExpectStatic): State;
|
259
261
|
declare function setState<State extends MatcherState = MatcherState>(state: Partial<State>, expect: ExpectStatic): void;
|
@@ -262,4 +264,4 @@ declare const JestChaiExpect: ChaiPlugin;
|
|
262
264
|
|
263
265
|
declare const JestExtend: ChaiPlugin;
|
264
266
|
|
265
|
-
export { 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 RawMatcherFn, StringContaining, StringMatching, type SyncExpectationResult, type Tester, arrayBufferEquality, equals, fnNameFor, generateToBeMessage, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, iterableEquality, pluralize, setState, sparseArrayEquality, subsetEquality, typeEquality };
|
267
|
+
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 RawMatcherFn, StringContaining, StringMatching, type SyncExpectationResult, type Tester, arrayBufferEquality, equals, fnNameFor, generateToBeMessage, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, iterableEquality, pluralize, setState, sparseArrayEquality, subsetEquality, typeEquality };
|
package/dist/index.js
CHANGED
@@ -8,10 +8,12 @@ import { util } from 'chai';
|
|
8
8
|
const MATCHERS_OBJECT = Symbol.for("matchers-object");
|
9
9
|
const JEST_MATCHERS_OBJECT = Symbol.for("$$jest-matchers-object");
|
10
10
|
const GLOBAL_EXPECT = Symbol.for("expect-global");
|
11
|
+
const ASYMMETRIC_MATCHERS_OBJECT = Symbol.for("asymmetric-matchers-object");
|
11
12
|
|
12
13
|
if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) {
|
13
14
|
const globalState = /* @__PURE__ */ new WeakMap();
|
14
15
|
const matchers = /* @__PURE__ */ Object.create(null);
|
16
|
+
const assymetricMatchers = /* @__PURE__ */ Object.create(null);
|
15
17
|
Object.defineProperty(globalThis, MATCHERS_OBJECT, {
|
16
18
|
get: () => globalState
|
17
19
|
});
|
@@ -22,6 +24,9 @@ if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) {
|
|
22
24
|
matchers
|
23
25
|
})
|
24
26
|
});
|
27
|
+
Object.defineProperty(globalThis, ASYMMETRIC_MATCHERS_OBJECT, {
|
28
|
+
get: () => assymetricMatchers
|
29
|
+
});
|
25
30
|
}
|
26
31
|
function getState(expect) {
|
27
32
|
return globalThis[MATCHERS_OBJECT].get(expect);
|
@@ -425,6 +430,7 @@ class AsymmetricMatcher {
|
|
425
430
|
...getState(expect || globalThis[GLOBAL_EXPECT]),
|
426
431
|
equals,
|
427
432
|
isNot: this.inverse,
|
433
|
+
customTesters: [],
|
428
434
|
utils: {
|
429
435
|
...getMatcherUtils(),
|
430
436
|
diff,
|
@@ -843,6 +849,32 @@ const JestChaiExpect = (chai, utils) => {
|
|
843
849
|
return this.match(expected);
|
844
850
|
});
|
845
851
|
def("toContain", function(item) {
|
852
|
+
const actual = this._obj;
|
853
|
+
if (typeof Node !== "undefined" && actual instanceof Node) {
|
854
|
+
if (!(item instanceof Node))
|
855
|
+
throw new TypeError(`toContain() expected a DOM node as the argument, but got ${typeof item}`);
|
856
|
+
return this.assert(
|
857
|
+
actual.contains(item),
|
858
|
+
"expected #{this} to contain element #{exp}",
|
859
|
+
"expected #{this} not to contain element #{exp}",
|
860
|
+
item,
|
861
|
+
actual
|
862
|
+
);
|
863
|
+
}
|
864
|
+
if (typeof DOMTokenList !== "undefined" && actual instanceof DOMTokenList) {
|
865
|
+
assertTypes(item, "class name", ["string"]);
|
866
|
+
const isNot = utils.flag(this, "negate");
|
867
|
+
const expectedClassList = isNot ? actual.value.replace(item, "").trim() : `${actual.value} ${item}`;
|
868
|
+
return this.assert(
|
869
|
+
actual.contains(item),
|
870
|
+
`expected "${actual.value}" to contain "${item}"`,
|
871
|
+
`expected "${actual.value}" not to contain "${item}"`,
|
872
|
+
expectedClassList,
|
873
|
+
actual.value
|
874
|
+
);
|
875
|
+
}
|
876
|
+
if (actual != null && typeof actual !== "string")
|
877
|
+
utils.flag(this, "object", Array.from(actual));
|
846
878
|
return this.contain(item);
|
847
879
|
});
|
848
880
|
def("toContainEqual", function(expected) {
|
@@ -1327,6 +1359,7 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
|
|
1327
1359
|
`promise rejected "${utils.inspect(err)}" instead of resolving`,
|
1328
1360
|
{ showDiff: false }
|
1329
1361
|
);
|
1362
|
+
_error.cause = err;
|
1330
1363
|
_error.stack = error.stack.replace(error.message, _error.message);
|
1331
1364
|
throw _error;
|
1332
1365
|
}
|
@@ -1356,7 +1389,7 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
|
|
1356
1389
|
(value) => {
|
1357
1390
|
const _error = new AssertionError(
|
1358
1391
|
`promise resolved "${utils.inspect(value)}" instead of rejecting`,
|
1359
|
-
{ showDiff:
|
1392
|
+
{ showDiff: true, expected: new Error("rejected promise"), actual: value }
|
1360
1393
|
);
|
1361
1394
|
_error.stack = error.stack.replace(error.message, _error.message);
|
1362
1395
|
throw _error;
|
@@ -1387,6 +1420,8 @@ function getMatcherState(assertion, expect) {
|
|
1387
1420
|
};
|
1388
1421
|
const matcherState = {
|
1389
1422
|
...getState(expect),
|
1423
|
+
// TODO: implement via expect.addEqualityTesters
|
1424
|
+
customTesters: [],
|
1390
1425
|
isNot,
|
1391
1426
|
utils: jestUtils,
|
1392
1427
|
promise,
|
@@ -1448,10 +1483,11 @@ function JestExtendPlugin(expect, matchers) {
|
|
1448
1483
|
return `${this.toString()}<${this.sample.map(String).join(", ")}>`;
|
1449
1484
|
}
|
1450
1485
|
}
|
1486
|
+
const customMatcher = (...sample) => new CustomMatcher(false, ...sample);
|
1451
1487
|
Object.defineProperty(expect, expectAssertionName, {
|
1452
1488
|
configurable: true,
|
1453
1489
|
enumerable: true,
|
1454
|
-
value:
|
1490
|
+
value: customMatcher,
|
1455
1491
|
writable: true
|
1456
1492
|
});
|
1457
1493
|
Object.defineProperty(expect.not, expectAssertionName, {
|
@@ -1460,6 +1496,12 @@ function JestExtendPlugin(expect, matchers) {
|
|
1460
1496
|
value: (...sample) => new CustomMatcher(true, ...sample),
|
1461
1497
|
writable: true
|
1462
1498
|
});
|
1499
|
+
Object.defineProperty(globalThis[ASYMMETRIC_MATCHERS_OBJECT], expectAssertionName, {
|
1500
|
+
configurable: true,
|
1501
|
+
enumerable: true,
|
1502
|
+
value: customMatcher,
|
1503
|
+
writable: true
|
1504
|
+
});
|
1463
1505
|
});
|
1464
1506
|
};
|
1465
1507
|
}
|
@@ -1469,4 +1511,4 @@ const JestExtend = (chai, utils) => {
|
|
1469
1511
|
});
|
1470
1512
|
};
|
1471
1513
|
|
1472
|
-
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, pluralize, setState, sparseArrayEquality, subsetEquality, typeEquality };
|
1514
|
+
export { ASYMMETRIC_MATCHERS_OBJECT, 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, pluralize, setState, sparseArrayEquality, subsetEquality, typeEquality };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/expect",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.0.0-beta.
|
4
|
+
"version": "1.0.0-beta.5",
|
5
5
|
"description": "Jest's expect matchers as a Chai plugin",
|
6
6
|
"license": "MIT",
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
@@ -18,7 +18,7 @@
|
|
18
18
|
"exports": {
|
19
19
|
".": {
|
20
20
|
"types": "./index.d.ts",
|
21
|
-
"
|
21
|
+
"default": "./dist/index.js"
|
22
22
|
},
|
23
23
|
"./*": "./*"
|
24
24
|
},
|
@@ -26,19 +26,19 @@
|
|
26
26
|
"module": "./dist/index.js",
|
27
27
|
"types": "./index.d.ts",
|
28
28
|
"files": [
|
29
|
-
"
|
30
|
-
"
|
29
|
+
"*.d.ts",
|
30
|
+
"dist"
|
31
31
|
],
|
32
32
|
"dependencies": {
|
33
33
|
"chai": "^4.3.10",
|
34
|
-
"@vitest/
|
35
|
-
"@vitest/
|
34
|
+
"@vitest/spy": "1.0.0-beta.5",
|
35
|
+
"@vitest/utils": "1.0.0-beta.5"
|
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.0.0-beta.
|
41
|
+
"@vitest/runner": "1.0.0-beta.5"
|
42
42
|
},
|
43
43
|
"scripts": {
|
44
44
|
"build": "rimraf dist && rollup -c",
|