jest-matcher-specific-error 0.0.8 → 1.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/README.md +16 -2
- package/dist/src/index.js +8 -6
- package/dist/src/matcher.js +4 -4
- package/package.json +17 -4
- package/types/vitest.d.ts +7 -0
package/README.md
CHANGED
|
@@ -11,7 +11,21 @@ With yarn:
|
|
|
11
11
|
> yarn add -D jest-matcher-specific-error
|
|
12
12
|
|
|
13
13
|
# Setup
|
|
14
|
-
|
|
14
|
+
Jest: same as [Other Jest matchers](https://jest-extended.jestcommunity.dev/docs/getting-started/setup).
|
|
15
|
+
|
|
16
|
+
Vitest: add it to `setupFiles` (works with or without `globals: true`):
|
|
17
|
+
```typescript
|
|
18
|
+
// vitest.config.ts
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
test: { setupFiles: ["jest-matcher-specific-error"] },
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
# Typescript
|
|
25
|
+
|
|
26
|
+
Jest: same as [Other Jest matchers](https://jest-extended.jestcommunity.dev/docs/getting-started/typescript).
|
|
27
|
+
|
|
28
|
+
Vitest: add `"jest-matcher-specific-error/types/vitest"` to `compilerOptions.types` in `tsconfig.json`, or add `import "jest-matcher-specific-error/types/vitest";` to a `.d.ts` file.
|
|
15
29
|
|
|
16
30
|
# Usage
|
|
17
31
|
```typescript
|
|
@@ -24,7 +38,7 @@ expect(yourError).toMatchError(expectedError);
|
|
|
24
38
|
Errors threated as equal if ALL conditions satisfied:
|
|
25
39
|
* Errors are instances of same class (strict `===` comparison by reference)
|
|
26
40
|
* Error messages are equal
|
|
27
|
-
* All error public fields are deeply equal (default `jest` helper comparison)
|
|
41
|
+
* All error public fields are deeply equal (default `jest`/`vitest` helper comparison)
|
|
28
42
|
|
|
29
43
|
Error stack traces are ignored.
|
|
30
44
|
|
package/dist/src/index.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const matcher_1 = require("./matcher");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
// Jest exposes a global `expect`; Vitest always registers its own under this symbol, even without `globals: true`.
|
|
5
|
+
const globalExpect = typeof expect !== "undefined"
|
|
6
|
+
? expect
|
|
7
|
+
: global[Symbol.for("expect-global")];
|
|
8
|
+
if (globalExpect !== undefined) {
|
|
9
|
+
globalExpect.extend({ toMatchError: matcher_1.toMatchError });
|
|
7
10
|
}
|
|
8
11
|
else {
|
|
9
12
|
throw new Error([
|
|
10
|
-
"Unable to find Jest's global expect.",
|
|
11
|
-
"Please check you have added jest-
|
|
12
|
-
"See https://github.com/jest-community/jest-extended#setup for help.",
|
|
13
|
+
"Unable to find Jest's or Vitest's global expect.",
|
|
14
|
+
"Please check you have added jest-matcher-specific-error to setupFilesAfterEnv (Jest) or setupFiles (Vitest).",
|
|
13
15
|
].join("\n"));
|
|
14
16
|
}
|
package/dist/src/matcher.js
CHANGED
|
@@ -32,13 +32,13 @@ function toMatchError(gotErrorFactory, expectedError) {
|
|
|
32
32
|
else {
|
|
33
33
|
const got = errorToObject(gotError);
|
|
34
34
|
if (got.class !== expected.class) {
|
|
35
|
-
diff.push("Error class is not the same:", this.utils.diff(
|
|
35
|
+
diff.push("Error class is not the same:", this.utils.diff(expected.class, got.class));
|
|
36
36
|
}
|
|
37
37
|
if (got.message !== expected.message) {
|
|
38
|
-
diff.push("Error message is not the same:", this.utils.diff(
|
|
38
|
+
diff.push("Error message is not the same:", this.utils.diff(expected.message, got.message));
|
|
39
39
|
}
|
|
40
|
-
if (!this.equals(
|
|
41
|
-
diff.push("Error public fields
|
|
40
|
+
if (!this.equals(expected.publicFields, got.publicFields)) {
|
|
41
|
+
diff.push("Error public fields are not the same:", this.utils.diff(expected.publicFields, got.publicFields));
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
return {
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jest-matcher-specific-error",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Make sure your function really throws what you expect",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
7
|
-
"repository":
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/DanielHreben/jest-matcher-specific-error.git"
|
|
10
|
+
},
|
|
8
11
|
"author": "Daniel Hreben <daniel.hreben@gmail.com>",
|
|
9
12
|
"license": "MIT",
|
|
10
13
|
"private": false,
|
|
@@ -25,8 +28,15 @@
|
|
|
25
28
|
"prepare": "yarn build",
|
|
26
29
|
"build": "rm -rf ./dist; tsc",
|
|
27
30
|
"lint:check": "eslint . --ext .ts",
|
|
31
|
+
"lint:lockfile": "lockfile-lint --path yarn.lock",
|
|
28
32
|
"lint": "yarn lint:check --fix",
|
|
29
|
-
"test": "jest"
|
|
33
|
+
"test": "jest",
|
|
34
|
+
"test:vitest": "vitest run test/vitest.test.mjs"
|
|
35
|
+
},
|
|
36
|
+
"lockfile-lint": {
|
|
37
|
+
"allowed-hosts": [
|
|
38
|
+
"npm"
|
|
39
|
+
]
|
|
30
40
|
},
|
|
31
41
|
"devDependencies": {
|
|
32
42
|
"@types/jest": "^26.0.14",
|
|
@@ -42,9 +52,12 @@
|
|
|
42
52
|
"eslint-plugin-prettier": "^3.1.4",
|
|
43
53
|
"eslint-plugin-simple-import-sort": "^5.0.3",
|
|
44
54
|
"jest": "^26.4.2",
|
|
55
|
+
"lockfile-lint": "^4.12.1",
|
|
45
56
|
"prettier": "^2.1.2",
|
|
46
57
|
"strip-color": "^0.1.0",
|
|
47
58
|
"ts-jest": "^26.4.1",
|
|
48
|
-
"typescript": "^4.0.3"
|
|
59
|
+
"typescript": "^4.0.3",
|
|
60
|
+
"vite": "^8.3.5",
|
|
61
|
+
"vitest": "^5.0.5"
|
|
49
62
|
}
|
|
50
63
|
}
|