tinyexpect 0.4.1 → 0.5.1
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/LICENSE +1 -1
- package/README.md +28 -1
- package/index.js +10 -0
- package/index.ts +9 -0
- package/package.json +1 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
1
|
# tinyexpect
|
|
2
2
|
|
|
3
|
-
`expect` with 0 dependencies for
|
|
3
|
+
`expect` is a lightweight testing utility with 0 dependencies that provides a Jest-like assertion API for TypeScript/JavaScript projects that use the native Node.js test runner `node --test`.
|
|
4
|
+
|
|
5
|
+
## API Reference
|
|
6
|
+
|
|
7
|
+
### Matchers
|
|
8
|
+
|
|
9
|
+
- `toBe(value)`: Checks strict equality (including deep equality for objects)
|
|
10
|
+
- `toNotBe(value)`: Checks strict inequality
|
|
11
|
+
- `eitherOr(values[])`: Checks if value is included in an array of possible values
|
|
12
|
+
- `toBeNumber()`: Verifies value is a number
|
|
13
|
+
- `toBeNumberOrParsed()`: Verifies value is either a number or can be parsed as one
|
|
14
|
+
- `toBeNumberOr(values[])`: Verifies value is either a number or one of the specified strings
|
|
15
|
+
- `toBeFalsy()`: Checks if value is falsy
|
|
16
|
+
- `toBeTruthy()`: Checks if value is truthy
|
|
17
|
+
- `toBeDefined()`: Verifies value is not undefined
|
|
18
|
+
- `toContainString(str)`: Checks if string contains a substring
|
|
19
|
+
- `toNotContainString(str)`: Checks if string does not contain a substring
|
|
20
|
+
|
|
21
|
+
## Error Handling
|
|
22
|
+
|
|
23
|
+
All matchers throw descriptive errors when assertions fail, including:
|
|
24
|
+
- Detailed error messages for object comparisons
|
|
25
|
+
- Type mismatch notifications
|
|
26
|
+
- Clear expected vs actual value reporting
|
|
27
|
+
|
|
28
|
+
## License
|
|
29
|
+
|
|
30
|
+
MIT
|
package/index.js
CHANGED
|
@@ -14,6 +14,16 @@ function expect(v) {
|
|
|
14
14
|
throw new Error(`Expected ${v} to be ${a}`);
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
|
+
toNotBe: (a) => {
|
|
18
|
+
if (typeof v === "object") {
|
|
19
|
+
if (JSON.stringify(v) === JSON.stringify(a)) {
|
|
20
|
+
throw new Error(`Expected ${JSON.stringify(v, null, 2)} to not be ${JSON.stringify(a, null, 2)}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else if (v === a) {
|
|
24
|
+
throw new Error(`Expected ${v} to not be ${a}`);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
17
27
|
eitherOr: (values) => {
|
|
18
28
|
if (!values.includes(v)) {
|
|
19
29
|
throw new Error(`Expected ${v} to be either of the following values:` +
|
package/index.ts
CHANGED
|
@@ -10,6 +10,15 @@ export function expect(v: any) {
|
|
|
10
10
|
throw new Error(`Expected ${v} to be ${a}`);
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
|
+
toNotBe: (a: any) => {
|
|
14
|
+
if (typeof v === "object"){
|
|
15
|
+
if (JSON.stringify(v) === JSON.stringify(a)) {
|
|
16
|
+
throw new Error(`Expected ${JSON.stringify(v,null,2)} to not be ${JSON.stringify(a,null,2)}`);
|
|
17
|
+
}
|
|
18
|
+
} else if (v === a) {
|
|
19
|
+
throw new Error(`Expected ${v} to not be ${a}`);
|
|
20
|
+
}
|
|
21
|
+
},
|
|
13
22
|
eitherOr: (values: any[]) => {
|
|
14
23
|
if (!values.includes(v)) {
|
|
15
24
|
throw new Error(
|