@vitest/expect 0.34.4 → 0.34.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.js +35 -24
- package/package.json +4 -4
package/dist/index.js
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import { getColors, stringify, isObject, assertTypes } from '@vitest/utils';
|
2
2
|
export { setupColors } from '@vitest/utils';
|
3
3
|
import { diff } from '@vitest/utils/diff';
|
4
|
-
import { AssertionError, util } from 'chai';
|
5
4
|
import { isMockFunction } from '@vitest/spy';
|
6
5
|
import { processError } from '@vitest/utils/error';
|
6
|
+
import { 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");
|
@@ -665,6 +665,7 @@ function wrapSoft(utils, fn) {
|
|
665
665
|
}
|
666
666
|
|
667
667
|
const JestChaiExpect = (chai, utils) => {
|
668
|
+
const { AssertionError } = chai;
|
668
669
|
const c = () => getColors();
|
669
670
|
function def(name, fn) {
|
670
671
|
const addMethod = (n) => {
|
@@ -1067,18 +1068,15 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
|
|
1067
1068
|
);
|
1068
1069
|
if (called && isNot)
|
1069
1070
|
msg = formatCalls(spy, msg);
|
1070
|
-
if (called && isNot || !called && !isNot)
|
1071
|
-
|
1072
|
-
err.name = "AssertionError";
|
1073
|
-
throw err;
|
1074
|
-
}
|
1071
|
+
if (called && isNot || !called && !isNot)
|
1072
|
+
throw new AssertionError(msg);
|
1075
1073
|
});
|
1076
1074
|
def(["toHaveBeenCalledWith", "toBeCalledWith"], function(...args) {
|
1077
1075
|
const spy = getSpy(this);
|
1078
1076
|
const spyName = spy.getMockName();
|
1079
1077
|
const pass = spy.mock.calls.some((callArg) => equals(callArg, args, [iterableEquality]));
|
1080
1078
|
const isNot = utils.flag(this, "negate");
|
1081
|
-
|
1079
|
+
const msg = utils.getMessage(
|
1082
1080
|
this,
|
1083
1081
|
[
|
1084
1082
|
pass,
|
@@ -1087,12 +1085,8 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
|
|
1087
1085
|
args
|
1088
1086
|
]
|
1089
1087
|
);
|
1090
|
-
if (pass && isNot || !pass && !isNot)
|
1091
|
-
|
1092
|
-
const err = new Error(msg);
|
1093
|
-
err.name = "AssertionError";
|
1094
|
-
throw err;
|
1095
|
-
}
|
1088
|
+
if (pass && isNot || !pass && !isNot)
|
1089
|
+
throw new AssertionError(formatCalls(spy, msg, args));
|
1096
1090
|
});
|
1097
1091
|
def(["toHaveBeenNthCalledWith", "nthCalledWith"], function(times, ...args) {
|
1098
1092
|
const spy = getSpy(this);
|
@@ -1138,11 +1132,20 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
|
|
1138
1132
|
return;
|
1139
1133
|
}
|
1140
1134
|
} else {
|
1135
|
+
let isThrow = false;
|
1141
1136
|
try {
|
1142
1137
|
obj();
|
1143
1138
|
} catch (err) {
|
1139
|
+
isThrow = true;
|
1144
1140
|
thrown = err;
|
1145
1141
|
}
|
1142
|
+
if (!isThrow && !isNot) {
|
1143
|
+
const message = utils.flag(this, "message") || "expected function to throw an error, but it didn't";
|
1144
|
+
const error = {
|
1145
|
+
showDiff: false
|
1146
|
+
};
|
1147
|
+
throw new AssertionError(message, error, utils.flag(this, "ssfi"));
|
1148
|
+
}
|
1146
1149
|
}
|
1147
1150
|
if (typeof expected === "function") {
|
1148
1151
|
const name = expected.name || expected.prototype.constructor.name;
|
@@ -1208,7 +1211,7 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
|
|
1208
1211
|
const spyName = spy.getMockName();
|
1209
1212
|
const pass = spy.mock.results.some(({ type, value: result }) => type === "return" && equals(value, result));
|
1210
1213
|
const isNot = utils.flag(this, "negate");
|
1211
|
-
|
1214
|
+
const msg = utils.getMessage(
|
1212
1215
|
this,
|
1213
1216
|
[
|
1214
1217
|
pass,
|
@@ -1217,12 +1220,8 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
|
|
1217
1220
|
value
|
1218
1221
|
]
|
1219
1222
|
);
|
1220
|
-
if (pass && isNot || !pass && !isNot)
|
1221
|
-
|
1222
|
-
const err = new Error(msg);
|
1223
|
-
err.name = "AssertionError";
|
1224
|
-
throw err;
|
1225
|
-
}
|
1223
|
+
if (pass && isNot || !pass && !isNot)
|
1224
|
+
throw new AssertionError(formatReturns(spy, msg, value));
|
1226
1225
|
});
|
1227
1226
|
def(["toHaveLastReturnedWith", "lastReturnedWith"], function(value) {
|
1228
1227
|
const spy = getSpy(this);
|
@@ -1258,8 +1257,9 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
|
|
1258
1257
|
return this.be.satisfy(matcher, message);
|
1259
1258
|
});
|
1260
1259
|
utils.addProperty(chai.Assertion.prototype, "resolves", function __VITEST_RESOLVES__() {
|
1260
|
+
const error = new Error("resolves");
|
1261
1261
|
utils.flag(this, "promise", "resolves");
|
1262
|
-
utils.flag(this, "error",
|
1262
|
+
utils.flag(this, "error", error);
|
1263
1263
|
const test = utils.flag(this, "vitest-test");
|
1264
1264
|
const obj = utils.flag(this, "object");
|
1265
1265
|
if (typeof (obj == null ? void 0 : obj.then) !== "function")
|
@@ -1276,7 +1276,12 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
|
|
1276
1276
|
return result.call(this, ...args);
|
1277
1277
|
},
|
1278
1278
|
(err) => {
|
1279
|
-
|
1279
|
+
const _error = new AssertionError(
|
1280
|
+
`promise rejected "${utils.inspect(err)}" instead of resolving`,
|
1281
|
+
{ showDiff: false }
|
1282
|
+
);
|
1283
|
+
_error.stack = error.stack.replace(error.message, _error.message);
|
1284
|
+
throw _error;
|
1280
1285
|
}
|
1281
1286
|
);
|
1282
1287
|
return recordAsyncExpect(test, promise);
|
@@ -1286,8 +1291,9 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
|
|
1286
1291
|
return proxy;
|
1287
1292
|
});
|
1288
1293
|
utils.addProperty(chai.Assertion.prototype, "rejects", function __VITEST_REJECTS__() {
|
1294
|
+
const error = new Error("rejects");
|
1289
1295
|
utils.flag(this, "promise", "rejects");
|
1290
|
-
utils.flag(this, "error",
|
1296
|
+
utils.flag(this, "error", error);
|
1291
1297
|
const test = utils.flag(this, "vitest-test");
|
1292
1298
|
const obj = utils.flag(this, "object");
|
1293
1299
|
const wrapper = typeof obj === "function" ? obj() : obj;
|
@@ -1301,7 +1307,12 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
|
|
1301
1307
|
return async (...args) => {
|
1302
1308
|
const promise = wrapper.then(
|
1303
1309
|
(value) => {
|
1304
|
-
|
1310
|
+
const _error = new AssertionError(
|
1311
|
+
`promise resolved "${utils.inspect(value)}" instead of rejecting`,
|
1312
|
+
{ showDiff: false }
|
1313
|
+
);
|
1314
|
+
_error.stack = error.stack.replace(error.message, _error.message);
|
1315
|
+
throw _error;
|
1305
1316
|
},
|
1306
1317
|
(err) => {
|
1307
1318
|
utils.flag(this, "object", err);
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/expect",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.34.
|
4
|
+
"version": "0.34.5",
|
5
5
|
"description": "Jest's expect matchers as a Chai plugin",
|
6
6
|
"license": "MIT",
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
@@ -30,12 +30,12 @@
|
|
30
30
|
],
|
31
31
|
"dependencies": {
|
32
32
|
"chai": "^4.3.7",
|
33
|
-
"@vitest/utils": "0.34.
|
34
|
-
"@vitest/spy": "0.34.
|
33
|
+
"@vitest/utils": "0.34.5",
|
34
|
+
"@vitest/spy": "0.34.5"
|
35
35
|
},
|
36
36
|
"devDependencies": {
|
37
37
|
"picocolors": "^1.0.0",
|
38
|
-
"@vitest/runner": "0.34.
|
38
|
+
"@vitest/runner": "0.34.5"
|
39
39
|
},
|
40
40
|
"scripts": {
|
41
41
|
"build": "rimraf dist && rollup -c",
|