@clipboard-health/testing-core 0.17.0 → 0.18.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 +60 -10
- package/package.json +2 -2
- package/src/index.d.ts +2 -0
- package/src/index.js +2 -0
- package/src/index.js.map +1 -1
- package/src/lib/expectToBeFailure.d.ts +5 -0
- package/src/lib/expectToBeFailure.js +14 -0
- package/src/lib/expectToBeFailure.js.map +1 -0
- package/src/lib/expectToBeSuccess.d.ts +5 -0
- package/src/lib/expectToBeSuccess.js +14 -0
- package/src/lib/expectToBeSuccess.js.map +1 -0
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ This library's helpers narrow types:
|
|
|
37
37
|
<embedex source="packages/testing-core/examples/expectToBeDefined.ts">
|
|
38
38
|
|
|
39
39
|
```ts
|
|
40
|
-
import {
|
|
40
|
+
import { strictEqual } from "node:assert/strict";
|
|
41
41
|
|
|
42
42
|
import { expectToBeDefined } from "@clipboard-health/testing-core";
|
|
43
43
|
|
|
@@ -50,7 +50,7 @@ expectToBeDefined(value);
|
|
|
50
50
|
|
|
51
51
|
// Narrowed to `string`
|
|
52
52
|
const { length } = value;
|
|
53
|
-
|
|
53
|
+
strictEqual(length, 2);
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
</embedex>
|
|
@@ -58,7 +58,7 @@ ok(length === 2);
|
|
|
58
58
|
<embedex source="packages/testing-core/examples/expectToBeLeft.ts">
|
|
59
59
|
|
|
60
60
|
```ts
|
|
61
|
-
import {
|
|
61
|
+
import { strictEqual } from "node:assert/strict";
|
|
62
62
|
|
|
63
63
|
import { expectToBeLeft } from "@clipboard-health/testing-core";
|
|
64
64
|
import { either as E } from "@clipboard-health/util-ts";
|
|
@@ -75,7 +75,7 @@ const value = divide(10, 0);
|
|
|
75
75
|
expectToBeLeft(value);
|
|
76
76
|
|
|
77
77
|
// Narrowed to Left
|
|
78
|
-
|
|
78
|
+
strictEqual(value.left, "Cannot divide by zero");
|
|
79
79
|
```
|
|
80
80
|
|
|
81
81
|
</embedex>
|
|
@@ -83,7 +83,7 @@ ok(value.left === "Cannot divide by zero");
|
|
|
83
83
|
<embedex source="packages/testing-core/examples/expectToBeRight.ts">
|
|
84
84
|
|
|
85
85
|
```ts
|
|
86
|
-
import {
|
|
86
|
+
import { strictEqual } from "node:assert/strict";
|
|
87
87
|
|
|
88
88
|
import { expectToBeRight } from "@clipboard-health/testing-core";
|
|
89
89
|
import { either as E } from "@clipboard-health/util-ts";
|
|
@@ -100,7 +100,57 @@ const value = divide(10, 2);
|
|
|
100
100
|
expectToBeRight(value);
|
|
101
101
|
|
|
102
102
|
// Narrowed to Right
|
|
103
|
-
|
|
103
|
+
strictEqual(value.right, 5);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
</embedex>
|
|
107
|
+
|
|
108
|
+
<embedex source="packages/testing-core/examples/expectToBeFailure.ts">
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import { strictEqual } from "node:assert/strict";
|
|
112
|
+
|
|
113
|
+
import { expectToBeFailure } from "@clipboard-health/testing-core";
|
|
114
|
+
import { failure, type ServiceResult, success } from "@clipboard-health/util-ts";
|
|
115
|
+
|
|
116
|
+
function validateAge(age: number): ServiceResult<number> {
|
|
117
|
+
if (age < 0) {
|
|
118
|
+
return failure({ issues: [{ code: "INVALID_AGE", message: "Age cannot be negative" }] });
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return success(age);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const result = validateAge(-5);
|
|
125
|
+
expectToBeFailure(result);
|
|
126
|
+
|
|
127
|
+
// Narrowed to Left (Failure)
|
|
128
|
+
strictEqual(result.left.issues[0]?.message, "Age cannot be negative");
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
</embedex>
|
|
132
|
+
|
|
133
|
+
<embedex source="packages/testing-core/examples/expectToBeSuccess.ts">
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import { strictEqual } from "node:assert/strict";
|
|
137
|
+
|
|
138
|
+
import { expectToBeSuccess } from "@clipboard-health/testing-core";
|
|
139
|
+
import { failure, type ServiceResult, success } from "@clipboard-health/util-ts";
|
|
140
|
+
|
|
141
|
+
function validateAge(age: number): ServiceResult<number> {
|
|
142
|
+
if (age < 0) {
|
|
143
|
+
return failure({ issues: [{ code: "INVALID_AGE", message: "Age cannot be negative" }] });
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return success(age);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const result = validateAge(25);
|
|
150
|
+
expectToBeSuccess(result);
|
|
151
|
+
|
|
152
|
+
// Narrowed to Right (Success)
|
|
153
|
+
strictEqual(result.right, 25);
|
|
104
154
|
```
|
|
105
155
|
|
|
106
156
|
</embedex>
|
|
@@ -108,7 +158,7 @@ ok(value.right === 5);
|
|
|
108
158
|
<embedex source="packages/testing-core/examples/expectToBeSafeParseError.ts">
|
|
109
159
|
|
|
110
160
|
```ts
|
|
111
|
-
import {
|
|
161
|
+
import { strictEqual } from "node:assert/strict";
|
|
112
162
|
|
|
113
163
|
import { expectToBeDefined, expectToBeSafeParseError } from "@clipboard-health/testing-core";
|
|
114
164
|
import { z } from "zod";
|
|
@@ -123,7 +173,7 @@ const firstIssue = value.error.issues[0];
|
|
|
123
173
|
expectToBeDefined(firstIssue);
|
|
124
174
|
|
|
125
175
|
// Narrowed to `ZodIssue`
|
|
126
|
-
|
|
176
|
+
strictEqual(firstIssue.message, "Expected string, received number");
|
|
127
177
|
```
|
|
128
178
|
|
|
129
179
|
</embedex>
|
|
@@ -131,7 +181,7 @@ ok(firstIssue.message === "Expected string, received number");
|
|
|
131
181
|
<embedex source="packages/testing-core/examples/expectToBeSafeParseSuccess.ts">
|
|
132
182
|
|
|
133
183
|
```ts
|
|
134
|
-
import {
|
|
184
|
+
import { strictEqual } from "node:assert/strict";
|
|
135
185
|
|
|
136
186
|
import { expectToBeSafeParseSuccess } from "@clipboard-health/testing-core";
|
|
137
187
|
import { z } from "zod";
|
|
@@ -142,7 +192,7 @@ const value = schema.safeParse({ name: "hi" });
|
|
|
142
192
|
expectToBeSafeParseSuccess(value);
|
|
143
193
|
|
|
144
194
|
// Narrowed to `SafeParseSuccess`
|
|
145
|
-
|
|
195
|
+
strictEqual(value.data.name, "hi");
|
|
146
196
|
```
|
|
147
197
|
|
|
148
198
|
</embedex>
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clipboard-health/testing-core",
|
|
3
3
|
"description": "TypeScript-friendly testing utilities.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.18.0",
|
|
5
5
|
"bugs": "https://github.com/ClipboardHealth/core-utils/issues",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@clipboard-health/util-ts": "3.
|
|
7
|
+
"@clipboard-health/util-ts": "3.9.0",
|
|
8
8
|
"tslib": "2.8.1"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
package/src/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from "./lib/expectToBeDefined";
|
|
2
|
+
export * from "./lib/expectToBeFailure";
|
|
2
3
|
export * from "./lib/expectToBeLeft";
|
|
3
4
|
export * from "./lib/expectToBeRight";
|
|
4
5
|
export * from "./lib/expectToBeSafeParseError";
|
|
5
6
|
export * from "./lib/expectToBeSafeParseSuccess";
|
|
7
|
+
export * from "./lib/expectToBeSuccess";
|
package/src/index.js
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./lib/expectToBeDefined"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./lib/expectToBeFailure"), exports);
|
|
5
6
|
tslib_1.__exportStar(require("./lib/expectToBeLeft"), exports);
|
|
6
7
|
tslib_1.__exportStar(require("./lib/expectToBeRight"), exports);
|
|
7
8
|
tslib_1.__exportStar(require("./lib/expectToBeSafeParseError"), exports);
|
|
8
9
|
tslib_1.__exportStar(require("./lib/expectToBeSafeParseSuccess"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./lib/expectToBeSuccess"), exports);
|
|
9
11
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/testing-core/src/index.ts"],"names":[],"mappings":";;;AAAA,kEAAwC;AACxC,+DAAqC;AACrC,gEAAsC;AACtC,yEAA+C;AAC/C,2EAAiD"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/testing-core/src/index.ts"],"names":[],"mappings":";;;AAAA,kEAAwC;AACxC,kEAAwC;AACxC,+DAAqC;AACrC,gEAAsC;AACtC,yEAA+C;AAC/C,2EAAiD;AACjD,kEAAwC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type either as E, type Failure, type ServiceError, type ServiceResult } from "@clipboard-health/util-ts";
|
|
2
|
+
/**
|
|
3
|
+
* Alias for {@link expectToBeLeft}
|
|
4
|
+
*/
|
|
5
|
+
export declare function expectToBeFailure<A>(value: ServiceResult<A> | undefined): asserts value is E.Left<ServiceError> & Failure<ServiceError>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expectToBeFailure = expectToBeFailure;
|
|
4
|
+
const strict_1 = require("node:assert/strict");
|
|
5
|
+
const util_ts_1 = require("@clipboard-health/util-ts");
|
|
6
|
+
const expectToBeLeft_1 = require("./expectToBeLeft");
|
|
7
|
+
/**
|
|
8
|
+
* Alias for {@link expectToBeLeft}
|
|
9
|
+
*/
|
|
10
|
+
function expectToBeFailure(value) {
|
|
11
|
+
(0, expectToBeLeft_1.expectToBeLeft)(value);
|
|
12
|
+
(0, strict_1.ok)((0, util_ts_1.isFailure)(value));
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=expectToBeFailure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expectToBeFailure.js","sourceRoot":"","sources":["../../../../../packages/testing-core/src/lib/expectToBeFailure.ts"],"names":[],"mappings":";;AAeA,8CAKC;AApBD,+CAAwC;AAExC,uDAMmC;AAEnC,qDAAkD;AAElD;;GAEG;AACH,SAAgB,iBAAiB,CAC/B,KAAmC;IAEnC,IAAA,+BAAc,EAAC,KAAK,CAAC,CAAC;IACtB,IAAA,WAAE,EAAC,IAAA,mBAAS,EAAC,KAAK,CAAC,CAAC,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expectToBeSuccess = expectToBeSuccess;
|
|
4
|
+
const strict_1 = require("node:assert/strict");
|
|
5
|
+
const util_ts_1 = require("@clipboard-health/util-ts");
|
|
6
|
+
const expectToBeRight_1 = require("./expectToBeRight");
|
|
7
|
+
/**
|
|
8
|
+
* Alias for {@link expectToBeRight}
|
|
9
|
+
*/
|
|
10
|
+
function expectToBeSuccess(value) {
|
|
11
|
+
(0, expectToBeRight_1.expectToBeRight)(value);
|
|
12
|
+
(0, strict_1.ok)((0, util_ts_1.isSuccess)(value));
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=expectToBeSuccess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expectToBeSuccess.js","sourceRoot":"","sources":["../../../../../packages/testing-core/src/lib/expectToBeSuccess.ts"],"names":[],"mappings":";;AAcA,8CAKC;AAnBD,+CAAwC;AAExC,uDAKmC;AAEnC,uDAAoD;AAEpD;;GAEG;AACH,SAAgB,iBAAiB,CAC/B,KAAmC;IAEnC,IAAA,iCAAe,EAAC,KAAK,CAAC,CAAC;IACvB,IAAA,WAAE,EAAC,IAAA,mBAAS,EAAC,KAAK,CAAC,CAAC,CAAC;AACvB,CAAC"}
|