@vitest/expect 2.1.0-beta.6 → 2.1.0
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.js +89 -86
- package/package.json +4 -4
package/dist/index.js
CHANGED
@@ -38,8 +38,11 @@ function getState(expect) {
|
|
38
38
|
function setState(state, expect) {
|
39
39
|
const map = globalThis[MATCHERS_OBJECT];
|
40
40
|
const current = map.get(expect) || {};
|
41
|
-
Object.
|
42
|
-
|
41
|
+
const results = Object.defineProperties(current, {
|
42
|
+
...Object.getOwnPropertyDescriptors(current),
|
43
|
+
...Object.getOwnPropertyDescriptors(state)
|
44
|
+
});
|
45
|
+
map.set(expect, results);
|
43
46
|
}
|
44
47
|
|
45
48
|
const EXPECTED_COLOR = c.green;
|
@@ -1316,95 +1319,17 @@ const JestChaiExpect = (chai, utils) => {
|
|
1316
1319
|
false
|
1317
1320
|
);
|
1318
1321
|
});
|
1319
|
-
|
1322
|
+
function assertIsMock(assertion) {
|
1320
1323
|
if (!isMockFunction(assertion._obj)) {
|
1321
1324
|
throw new TypeError(
|
1322
1325
|
`${utils.inspect(assertion._obj)} is not a spy or a call to a spy!`
|
1323
1326
|
);
|
1324
1327
|
}
|
1325
|
-
}
|
1326
|
-
|
1328
|
+
}
|
1329
|
+
function getSpy(assertion) {
|
1327
1330
|
assertIsMock(assertion);
|
1328
1331
|
return assertion._obj;
|
1329
|
-
}
|
1330
|
-
const ordinalOf = (i) => {
|
1331
|
-
const j = i % 10;
|
1332
|
-
const k = i % 100;
|
1333
|
-
if (j === 1 && k !== 11) {
|
1334
|
-
return `${i}st`;
|
1335
|
-
}
|
1336
|
-
if (j === 2 && k !== 12) {
|
1337
|
-
return `${i}nd`;
|
1338
|
-
}
|
1339
|
-
if (j === 3 && k !== 13) {
|
1340
|
-
return `${i}rd`;
|
1341
|
-
}
|
1342
|
-
return `${i}th`;
|
1343
|
-
};
|
1344
|
-
const formatCalls = (spy, msg, showActualCall) => {
|
1345
|
-
if (spy.mock.calls) {
|
1346
|
-
msg += c.gray(
|
1347
|
-
`
|
1348
|
-
|
1349
|
-
Received:
|
1350
|
-
|
1351
|
-
${spy.mock.calls.map((callArg, i) => {
|
1352
|
-
let methodCall = c.bold(
|
1353
|
-
` ${ordinalOf(i + 1)} ${spy.getMockName()} call:
|
1354
|
-
|
1355
|
-
`
|
1356
|
-
);
|
1357
|
-
if (showActualCall) {
|
1358
|
-
methodCall += diff(showActualCall, callArg, {
|
1359
|
-
omitAnnotationLines: true
|
1360
|
-
});
|
1361
|
-
} else {
|
1362
|
-
methodCall += stringify(callArg).split("\n").map((line) => ` ${line}`).join("\n");
|
1363
|
-
}
|
1364
|
-
methodCall += "\n";
|
1365
|
-
return methodCall;
|
1366
|
-
}).join("\n")}`
|
1367
|
-
);
|
1368
|
-
}
|
1369
|
-
msg += c.gray(
|
1370
|
-
`
|
1371
|
-
|
1372
|
-
Number of calls: ${c.bold(spy.mock.calls.length)}
|
1373
|
-
`
|
1374
|
-
);
|
1375
|
-
return msg;
|
1376
|
-
};
|
1377
|
-
const formatReturns = (spy, results, msg, showActualReturn) => {
|
1378
|
-
msg += c.gray(
|
1379
|
-
`
|
1380
|
-
|
1381
|
-
Received:
|
1382
|
-
|
1383
|
-
${results.map((callReturn, i) => {
|
1384
|
-
let methodCall = c.bold(
|
1385
|
-
` ${ordinalOf(i + 1)} ${spy.getMockName()} call return:
|
1386
|
-
|
1387
|
-
`
|
1388
|
-
);
|
1389
|
-
if (showActualReturn) {
|
1390
|
-
methodCall += diff(showActualReturn, callReturn.value, {
|
1391
|
-
omitAnnotationLines: true
|
1392
|
-
});
|
1393
|
-
} else {
|
1394
|
-
methodCall += stringify(callReturn).split("\n").map((line) => ` ${line}`).join("\n");
|
1395
|
-
}
|
1396
|
-
methodCall += "\n";
|
1397
|
-
return methodCall;
|
1398
|
-
}).join("\n")}`
|
1399
|
-
);
|
1400
|
-
msg += c.gray(
|
1401
|
-
`
|
1402
|
-
|
1403
|
-
Number of calls: ${c.bold(spy.mock.calls.length)}
|
1404
|
-
`
|
1405
|
-
);
|
1406
|
-
return msg;
|
1407
|
-
};
|
1332
|
+
}
|
1408
1333
|
def(["toHaveBeenCalledTimes", "toBeCalledTimes"], function(number) {
|
1409
1334
|
const spy = getSpy(this);
|
1410
1335
|
const spyName = spy.getMockName();
|
@@ -1767,7 +1692,7 @@ Number of calls: ${c.bold(spy.mock.calls.length)}
|
|
1767
1692
|
if (typeof result !== "function") {
|
1768
1693
|
return result instanceof chai.Assertion ? proxy : result;
|
1769
1694
|
}
|
1770
|
-
return
|
1695
|
+
return (...args) => {
|
1771
1696
|
const promise = obj.then(
|
1772
1697
|
(value) => {
|
1773
1698
|
utils.flag(this, "object", value);
|
@@ -1821,7 +1746,7 @@ Number of calls: ${c.bold(spy.mock.calls.length)}
|
|
1821
1746
|
if (typeof result !== "function") {
|
1822
1747
|
return result instanceof chai.Assertion ? proxy : result;
|
1823
1748
|
}
|
1824
|
-
return
|
1749
|
+
return (...args) => {
|
1825
1750
|
const promise = wrapper.then(
|
1826
1751
|
(value) => {
|
1827
1752
|
const _error = new AssertionError(
|
@@ -1853,6 +1778,84 @@ Number of calls: ${c.bold(spy.mock.calls.length)}
|
|
1853
1778
|
}
|
1854
1779
|
);
|
1855
1780
|
};
|
1781
|
+
function ordinalOf(i) {
|
1782
|
+
const j = i % 10;
|
1783
|
+
const k = i % 100;
|
1784
|
+
if (j === 1 && k !== 11) {
|
1785
|
+
return `${i}st`;
|
1786
|
+
}
|
1787
|
+
if (j === 2 && k !== 12) {
|
1788
|
+
return `${i}nd`;
|
1789
|
+
}
|
1790
|
+
if (j === 3 && k !== 13) {
|
1791
|
+
return `${i}rd`;
|
1792
|
+
}
|
1793
|
+
return `${i}th`;
|
1794
|
+
}
|
1795
|
+
function formatCalls(spy, msg, showActualCall) {
|
1796
|
+
if (spy.mock.calls) {
|
1797
|
+
msg += c.gray(
|
1798
|
+
`
|
1799
|
+
|
1800
|
+
Received:
|
1801
|
+
|
1802
|
+
${spy.mock.calls.map((callArg, i) => {
|
1803
|
+
let methodCall = c.bold(
|
1804
|
+
` ${ordinalOf(i + 1)} ${spy.getMockName()} call:
|
1805
|
+
|
1806
|
+
`
|
1807
|
+
);
|
1808
|
+
if (showActualCall) {
|
1809
|
+
methodCall += diff(showActualCall, callArg, {
|
1810
|
+
omitAnnotationLines: true
|
1811
|
+
});
|
1812
|
+
} else {
|
1813
|
+
methodCall += stringify(callArg).split("\n").map((line) => ` ${line}`).join("\n");
|
1814
|
+
}
|
1815
|
+
methodCall += "\n";
|
1816
|
+
return methodCall;
|
1817
|
+
}).join("\n")}`
|
1818
|
+
);
|
1819
|
+
}
|
1820
|
+
msg += c.gray(
|
1821
|
+
`
|
1822
|
+
|
1823
|
+
Number of calls: ${c.bold(spy.mock.calls.length)}
|
1824
|
+
`
|
1825
|
+
);
|
1826
|
+
return msg;
|
1827
|
+
}
|
1828
|
+
function formatReturns(spy, results, msg, showActualReturn) {
|
1829
|
+
msg += c.gray(
|
1830
|
+
`
|
1831
|
+
|
1832
|
+
Received:
|
1833
|
+
|
1834
|
+
${results.map((callReturn, i) => {
|
1835
|
+
let methodCall = c.bold(
|
1836
|
+
` ${ordinalOf(i + 1)} ${spy.getMockName()} call return:
|
1837
|
+
|
1838
|
+
`
|
1839
|
+
);
|
1840
|
+
if (showActualReturn) {
|
1841
|
+
methodCall += diff(showActualReturn, callReturn.value, {
|
1842
|
+
omitAnnotationLines: true
|
1843
|
+
});
|
1844
|
+
} else {
|
1845
|
+
methodCall += stringify(callReturn).split("\n").map((line) => ` ${line}`).join("\n");
|
1846
|
+
}
|
1847
|
+
methodCall += "\n";
|
1848
|
+
return methodCall;
|
1849
|
+
}).join("\n")}`
|
1850
|
+
);
|
1851
|
+
msg += c.gray(
|
1852
|
+
`
|
1853
|
+
|
1854
|
+
Number of calls: ${c.bold(spy.mock.calls.length)}
|
1855
|
+
`
|
1856
|
+
);
|
1857
|
+
return msg;
|
1858
|
+
}
|
1856
1859
|
|
1857
1860
|
function getMatcherState(assertion, expect) {
|
1858
1861
|
const obj = assertion._obj;
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/expect",
|
3
3
|
"type": "module",
|
4
|
-
"version": "2.1.0
|
4
|
+
"version": "2.1.0",
|
5
5
|
"description": "Jest's expect matchers as a Chai plugin",
|
6
6
|
"license": "MIT",
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
@@ -32,13 +32,13 @@
|
|
32
32
|
"dependencies": {
|
33
33
|
"chai": "^5.1.1",
|
34
34
|
"tinyrainbow": "^1.2.0",
|
35
|
-
"@vitest/
|
36
|
-
"@vitest/
|
35
|
+
"@vitest/spy": "2.1.0",
|
36
|
+
"@vitest/utils": "2.1.0"
|
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.0
|
41
|
+
"@vitest/runner": "2.1.0"
|
42
42
|
},
|
43
43
|
"scripts": {
|
44
44
|
"build": "rimraf dist && rollup -c",
|