tinyexpect 0.3.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022 Mak Drakos
3
+ Copyright (c) 2024 crafter999
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,3 +1,30 @@
1
1
  # tinyexpect
2
2
 
3
- `expect` with 0 dependencies for testing using the native Node.js test runner `node --test`.
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:` +
@@ -61,6 +71,14 @@ function expect(v) {
61
71
  if (!v.includes(str)) {
62
72
  throw new Error(`${v} doesn't contain ${str}`);
63
73
  }
74
+ },
75
+ toNotContainString(str) {
76
+ if (typeof v !== "string") {
77
+ throw new Error(`${v} is not a string`);
78
+ }
79
+ if (v.includes(str)) {
80
+ throw new Error(`${v} contains ${str}`);
81
+ }
64
82
  }
65
83
  };
66
84
  }
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(
@@ -60,6 +69,15 @@ export function expect(v: any) {
60
69
  if (!(v as string).includes(str)){
61
70
  throw new Error(`${v} doesn't contain ${str}`)
62
71
  }
63
- }
72
+ },
73
+ toNotContainString(str:string){
74
+ if (typeof v !== "string"){
75
+ throw new Error(`${v} is not a string`)
76
+ }
77
+
78
+ if ((v as string).includes(str)){
79
+ throw new Error(`${v} contains ${str}`)
80
+ }
81
+ }
64
82
  }
65
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinyexpect",
3
- "version": "0.3.1",
3
+ "version": "0.5.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {