@vitest/expect 2.1.0-beta.6 → 2.1.0-beta.7
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 +84 -84
- package/package.json +4 -4
package/dist/index.js
CHANGED
@@ -1316,95 +1316,17 @@ const JestChaiExpect = (chai, utils) => {
|
|
1316
1316
|
false
|
1317
1317
|
);
|
1318
1318
|
});
|
1319
|
-
|
1319
|
+
function assertIsMock(assertion) {
|
1320
1320
|
if (!isMockFunction(assertion._obj)) {
|
1321
1321
|
throw new TypeError(
|
1322
1322
|
`${utils.inspect(assertion._obj)} is not a spy or a call to a spy!`
|
1323
1323
|
);
|
1324
1324
|
}
|
1325
|
-
}
|
1326
|
-
|
1325
|
+
}
|
1326
|
+
function getSpy(assertion) {
|
1327
1327
|
assertIsMock(assertion);
|
1328
1328
|
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
|
-
};
|
1329
|
+
}
|
1408
1330
|
def(["toHaveBeenCalledTimes", "toBeCalledTimes"], function(number) {
|
1409
1331
|
const spy = getSpy(this);
|
1410
1332
|
const spyName = spy.getMockName();
|
@@ -1767,7 +1689,7 @@ Number of calls: ${c.bold(spy.mock.calls.length)}
|
|
1767
1689
|
if (typeof result !== "function") {
|
1768
1690
|
return result instanceof chai.Assertion ? proxy : result;
|
1769
1691
|
}
|
1770
|
-
return
|
1692
|
+
return (...args) => {
|
1771
1693
|
const promise = obj.then(
|
1772
1694
|
(value) => {
|
1773
1695
|
utils.flag(this, "object", value);
|
@@ -1821,7 +1743,7 @@ Number of calls: ${c.bold(spy.mock.calls.length)}
|
|
1821
1743
|
if (typeof result !== "function") {
|
1822
1744
|
return result instanceof chai.Assertion ? proxy : result;
|
1823
1745
|
}
|
1824
|
-
return
|
1746
|
+
return (...args) => {
|
1825
1747
|
const promise = wrapper.then(
|
1826
1748
|
(value) => {
|
1827
1749
|
const _error = new AssertionError(
|
@@ -1853,6 +1775,84 @@ Number of calls: ${c.bold(spy.mock.calls.length)}
|
|
1853
1775
|
}
|
1854
1776
|
);
|
1855
1777
|
};
|
1778
|
+
function ordinalOf(i) {
|
1779
|
+
const j = i % 10;
|
1780
|
+
const k = i % 100;
|
1781
|
+
if (j === 1 && k !== 11) {
|
1782
|
+
return `${i}st`;
|
1783
|
+
}
|
1784
|
+
if (j === 2 && k !== 12) {
|
1785
|
+
return `${i}nd`;
|
1786
|
+
}
|
1787
|
+
if (j === 3 && k !== 13) {
|
1788
|
+
return `${i}rd`;
|
1789
|
+
}
|
1790
|
+
return `${i}th`;
|
1791
|
+
}
|
1792
|
+
function formatCalls(spy, msg, showActualCall) {
|
1793
|
+
if (spy.mock.calls) {
|
1794
|
+
msg += c.gray(
|
1795
|
+
`
|
1796
|
+
|
1797
|
+
Received:
|
1798
|
+
|
1799
|
+
${spy.mock.calls.map((callArg, i) => {
|
1800
|
+
let methodCall = c.bold(
|
1801
|
+
` ${ordinalOf(i + 1)} ${spy.getMockName()} call:
|
1802
|
+
|
1803
|
+
`
|
1804
|
+
);
|
1805
|
+
if (showActualCall) {
|
1806
|
+
methodCall += diff(showActualCall, callArg, {
|
1807
|
+
omitAnnotationLines: true
|
1808
|
+
});
|
1809
|
+
} else {
|
1810
|
+
methodCall += stringify(callArg).split("\n").map((line) => ` ${line}`).join("\n");
|
1811
|
+
}
|
1812
|
+
methodCall += "\n";
|
1813
|
+
return methodCall;
|
1814
|
+
}).join("\n")}`
|
1815
|
+
);
|
1816
|
+
}
|
1817
|
+
msg += c.gray(
|
1818
|
+
`
|
1819
|
+
|
1820
|
+
Number of calls: ${c.bold(spy.mock.calls.length)}
|
1821
|
+
`
|
1822
|
+
);
|
1823
|
+
return msg;
|
1824
|
+
}
|
1825
|
+
function formatReturns(spy, results, msg, showActualReturn) {
|
1826
|
+
msg += c.gray(
|
1827
|
+
`
|
1828
|
+
|
1829
|
+
Received:
|
1830
|
+
|
1831
|
+
${results.map((callReturn, i) => {
|
1832
|
+
let methodCall = c.bold(
|
1833
|
+
` ${ordinalOf(i + 1)} ${spy.getMockName()} call return:
|
1834
|
+
|
1835
|
+
`
|
1836
|
+
);
|
1837
|
+
if (showActualReturn) {
|
1838
|
+
methodCall += diff(showActualReturn, callReturn.value, {
|
1839
|
+
omitAnnotationLines: true
|
1840
|
+
});
|
1841
|
+
} else {
|
1842
|
+
methodCall += stringify(callReturn).split("\n").map((line) => ` ${line}`).join("\n");
|
1843
|
+
}
|
1844
|
+
methodCall += "\n";
|
1845
|
+
return methodCall;
|
1846
|
+
}).join("\n")}`
|
1847
|
+
);
|
1848
|
+
msg += c.gray(
|
1849
|
+
`
|
1850
|
+
|
1851
|
+
Number of calls: ${c.bold(spy.mock.calls.length)}
|
1852
|
+
`
|
1853
|
+
);
|
1854
|
+
return msg;
|
1855
|
+
}
|
1856
1856
|
|
1857
1857
|
function getMatcherState(assertion, expect) {
|
1858
1858
|
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-beta.
|
4
|
+
"version": "2.1.0-beta.7",
|
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/utils": "2.1.0-beta.
|
36
|
-
"@vitest/spy": "2.1.0-beta.
|
35
|
+
"@vitest/utils": "2.1.0-beta.7",
|
36
|
+
"@vitest/spy": "2.1.0-beta.7"
|
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-beta.
|
41
|
+
"@vitest/runner": "2.1.0-beta.7"
|
42
42
|
},
|
43
43
|
"scripts": {
|
44
44
|
"build": "rimraf dist && rollup -c",
|