@vitest/expect 2.1.2 → 2.1.3

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 CHANGED
@@ -243,7 +243,7 @@ declare function sparseArrayEquality(a: unknown, b: unknown, customTesters?: Arr
243
243
  declare function generateToBeMessage(deepEqualityName: string, expected?: string, actual?: string): string;
244
244
  declare function pluralize(word: string, count: number): string;
245
245
  declare function getObjectKeys(object: object): Array<string | symbol>;
246
- declare function getObjectSubset(object: any, subset: any, customTesters?: Array<Tester>): {
246
+ declare function getObjectSubset(object: any, subset: any, customTesters: Array<Tester>): {
247
247
  subset: any;
248
248
  stripped: number;
249
249
  };
package/dist/index.js CHANGED
@@ -555,7 +555,7 @@ function getObjectKeys(object) {
555
555
  )
556
556
  ];
557
557
  }
558
- function getObjectSubset(object, subset, customTesters = []) {
558
+ function getObjectSubset(object, subset, customTesters) {
559
559
  let stripped = 0;
560
560
  const getObjectSubsetWithContext = (seenReferences = /* @__PURE__ */ new WeakMap()) => (object2, subset2) => {
561
561
  if (Array.isArray(object2)) {
@@ -576,6 +576,12 @@ function getObjectSubset(object, subset, customTesters = []) {
576
576
  }
577
577
  const trimmed = {};
578
578
  seenReferences.set(object2, trimmed);
579
+ if (typeof object2.constructor === "function" && typeof object2.constructor.name === "string") {
580
+ Object.defineProperty(trimmed, "constructor", {
581
+ enumerable: false,
582
+ value: object2.constructor
583
+ });
584
+ }
579
585
  for (const key of getObjectKeys(object2)) {
580
586
  if (hasPropertyInObject(subset2, key)) {
581
587
  trimmed[key] = seenReferences.has(object2[key]) ? seenReferences.get(object2[key]) : getObjectSubsetWithContext(seenReferences)(
@@ -916,9 +922,10 @@ function recordAsyncExpect(test, promise) {
916
922
  }
917
923
  return promise;
918
924
  }
919
- function wrapSoft(utils, fn) {
925
+ function wrapAssertion(utils, name, fn) {
920
926
  return function(...args) {
921
927
  var _a;
928
+ utils.flag(this, "_name", name);
922
929
  if (!utils.flag(this, "soft")) {
923
930
  return fn.apply(this, args);
924
931
  }
@@ -942,7 +949,7 @@ const JestChaiExpect = (chai, utils) => {
942
949
  const customTesters = getCustomEqualityTesters();
943
950
  function def(name, fn) {
944
951
  const addMethod = (n) => {
945
- const softWrapper = wrapSoft(utils, fn);
952
+ const softWrapper = wrapAssertion(utils, n, fn);
946
953
  utils.addMethod(chai.Assertion.prototype, n, softWrapper);
947
954
  utils.addMethod(
948
955
  globalThis[JEST_MATCHERS_OBJECT].matchers,
@@ -1068,7 +1075,8 @@ const JestChaiExpect = (chai, utils) => {
1068
1075
  const isNot = utils.flag(this, "negate");
1069
1076
  const { subset: actualSubset, stripped } = getObjectSubset(
1070
1077
  actual,
1071
- expected
1078
+ expected,
1079
+ customTesters
1072
1080
  );
1073
1081
  if (pass && isNot || !pass && !isNot) {
1074
1082
  const msg = utils.getMessage(this, [
@@ -1163,8 +1171,8 @@ const JestChaiExpect = (chai, utils) => {
1163
1171
  Boolean(obj),
1164
1172
  "expected #{this} to be truthy",
1165
1173
  "expected #{this} to not be truthy",
1166
- obj,
1167
- false
1174
+ true,
1175
+ obj
1168
1176
  );
1169
1177
  });
1170
1178
  def("toBeFalsy", function() {
@@ -1173,8 +1181,8 @@ const JestChaiExpect = (chai, utils) => {
1173
1181
  !obj,
1174
1182
  "expected #{this} to be falsy",
1175
1183
  "expected #{this} to not be falsy",
1176
- obj,
1177
- false
1184
+ false,
1185
+ obj
1178
1186
  );
1179
1187
  });
1180
1188
  def("toBeGreaterThan", function(expected) {
@@ -1185,8 +1193,8 @@ const JestChaiExpect = (chai, utils) => {
1185
1193
  actual > expected,
1186
1194
  `expected ${actual} to be greater than ${expected}`,
1187
1195
  `expected ${actual} to be not greater than ${expected}`,
1188
- actual,
1189
1196
  expected,
1197
+ actual,
1190
1198
  false
1191
1199
  );
1192
1200
  });
@@ -1198,8 +1206,8 @@ const JestChaiExpect = (chai, utils) => {
1198
1206
  actual >= expected,
1199
1207
  `expected ${actual} to be greater than or equal to ${expected}`,
1200
1208
  `expected ${actual} to be not greater than or equal to ${expected}`,
1201
- actual,
1202
1209
  expected,
1210
+ actual,
1203
1211
  false
1204
1212
  );
1205
1213
  });
@@ -1211,8 +1219,8 @@ const JestChaiExpect = (chai, utils) => {
1211
1219
  actual < expected,
1212
1220
  `expected ${actual} to be less than ${expected}`,
1213
1221
  `expected ${actual} to be not less than ${expected}`,
1214
- actual,
1215
1222
  expected,
1223
+ actual,
1216
1224
  false
1217
1225
  );
1218
1226
  });
@@ -1224,19 +1232,40 @@ const JestChaiExpect = (chai, utils) => {
1224
1232
  actual <= expected,
1225
1233
  `expected ${actual} to be less than or equal to ${expected}`,
1226
1234
  `expected ${actual} to be not less than or equal to ${expected}`,
1227
- actual,
1228
1235
  expected,
1236
+ actual,
1229
1237
  false
1230
1238
  );
1231
1239
  });
1232
1240
  def("toBeNaN", function() {
1233
- return this.be.NaN;
1241
+ const obj = utils.flag(this, "object");
1242
+ this.assert(
1243
+ Number.isNaN(obj),
1244
+ "expected #{this} to be NaN",
1245
+ "expected #{this} not to be NaN",
1246
+ Number.NaN,
1247
+ obj
1248
+ );
1234
1249
  });
1235
1250
  def("toBeUndefined", function() {
1236
- return this.be.undefined;
1251
+ const obj = utils.flag(this, "object");
1252
+ this.assert(
1253
+ void 0 === obj,
1254
+ "expected #{this} to be undefined",
1255
+ "expected #{this} not to be undefined",
1256
+ void 0,
1257
+ obj
1258
+ );
1237
1259
  });
1238
1260
  def("toBeNull", function() {
1239
- return this.be.null;
1261
+ const obj = utils.flag(this, "object");
1262
+ this.assert(
1263
+ obj === null,
1264
+ "expected #{this} to be null",
1265
+ "expected #{this} not to be null",
1266
+ null,
1267
+ obj
1268
+ );
1240
1269
  });
1241
1270
  def("toBeDefined", function() {
1242
1271
  const obj = utils.flag(this, "object");
@@ -1913,7 +1942,7 @@ function JestExtendPlugin(c, expect, matchers) {
1913
1942
  throw new JestExtendError(message(), actual, expected);
1914
1943
  }
1915
1944
  }
1916
- const softWrapper = wrapSoft(utils, expectWrapper);
1945
+ const softWrapper = wrapAssertion(utils, expectAssertionName, expectWrapper);
1917
1946
  utils.addMethod(
1918
1947
  globalThis[JEST_MATCHERS_OBJECT].matchers,
1919
1948
  expectAssertionName,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/expect",
3
3
  "type": "module",
4
- "version": "2.1.2",
4
+ "version": "2.1.3",
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/spy": "2.1.2",
36
- "@vitest/utils": "2.1.2"
35
+ "@vitest/spy": "2.1.3",
36
+ "@vitest/utils": "2.1.3"
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.2"
41
+ "@vitest/runner": "2.1.3"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "rimraf dist && rollup -c",