@xylabs/vitest-extended 4.4.8 → 4.4.10

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.
@@ -1,26 +1,2 @@
1
- interface ExpectationResult {
2
- actual?: unknown;
3
- expected?: unknown;
4
- message: () => string;
5
- pass: boolean;
6
- }
7
- export declare const matchers: {
8
- toBeArrayOfSize(received: unknown, expectedSize: number): ExpectationResult;
9
- toBeArray(received: unknown): ExpectationResult;
10
- toBeOneOf(received: unknown, expected: unknown[]): ExpectationResult;
11
- toBeNegative(received: number): ExpectationResult;
12
- toBePositive(received: number): ExpectationResult;
13
- toBeNumber: (received: unknown) => ExpectationResult;
14
- toBeFunction: (received: unknown) => ExpectationResult;
15
- toBeString: (received: unknown) => ExpectationResult;
16
- toBeObject(received: unknown): ExpectationResult;
17
- toBeInteger(received: number): ExpectationResult;
18
- toBeFalse(received: unknown): ExpectationResult;
19
- toBeTrue(received: unknown): ExpectationResult;
20
- toIncludeAllMembers(received: unknown[], expected: unknown[]): ExpectationResult;
21
- toContainAllKeys(received: object, expectedKeys: string[]): ExpectationResult;
22
- toContainValues(received: object, expectedValues: unknown[]): ExpectationResult;
23
- toBeEmpty(received: unknown): ExpectationResult;
24
- };
25
1
  export {};
26
2
  //# sourceMappingURL=customMatchers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"customMatchers.d.ts","sourceRoot":"","sources":["../../src/customMatchers.ts"],"names":[],"mappings":"AAEA,UAAU,iBAAiB;IACzB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,OAAO,EAAE,MAAM,MAAM,CAAA;IACrB,IAAI,EAAE,OAAO,CAAA;CACd;AAeD,eAAO,MAAM,QAAQ;8BACO,OAAO,gBAAgB,MAAM,GAAG,iBAAiB;wBAcvD,OAAO,GAAG,iBAAiB;wBAY3B,OAAO,YAAY,OAAO,EAAE,GAAG,iBAAiB;2BAc7C,MAAM,GAAG,iBAAiB;2BAkB1B,MAAM,GAAG,iBAAiB;2BAkB1B,OAAO;6BACL,OAAO;2BACT,OAAO;yBACT,OAAO,GAAG,iBAAiB;0BAY1B,MAAM,GAAG,iBAAiB;wBAkB5B,OAAO,GAAG,iBAAiB;uBAY5B,OAAO,GAAG,iBAAiB;kCAYhB,OAAO,EAAE,YAAY,OAAO,EAAE,GAAG,iBAAiB;+BAwBrD,MAAM,gBAAgB,MAAM,EAAE,GAAG,iBAAiB;8BA+BnD,MAAM,kBAAkB,OAAO,EAAE,GAAG,iBAAiB;wBAgD3D,OAAO,GAAG,iBAAiB;CA6BhD,CAAA"}
1
+ {"version":3,"file":"customMatchers.d.ts","sourceRoot":"","sources":["../../src/customMatchers.ts"],"names":[],"mappings":""}
@@ -1,223 +1,5 @@
1
1
  // src/customMatchers.ts
2
+ import { matchers } from "@xylabs/vitest-matchers";
2
3
  import { expect } from "vitest";
3
- function toBeType(received, expectedType) {
4
- const pass = typeof received === expectedType && !Number.isNaN(received);
5
- return pass ? {
6
- message: () => `expected ${received} not to be a ${expectedType}`,
7
- pass: true
8
- } : {
9
- message: () => `expected ${received} to be a ${expectedType}`,
10
- pass: false
11
- };
12
- }
13
- var matchers = {
14
- toBeArrayOfSize(received, expectedSize) {
15
- const pass = Array.isArray(received) && received.length === expectedSize;
16
- return pass ? {
17
- message: () => `expected array not to have size ${expectedSize}, but received array of size ${received.length}`,
18
- pass: true
19
- } : {
20
- message: () => Array.isArray(received) ? `expected array of size ${expectedSize}, but received array of size ${received.length}` : `expected array of size ${expectedSize}, but received a non-array`,
21
- pass: false
22
- };
23
- },
24
- toBeArray(received) {
25
- const pass = Array.isArray(received);
26
- return pass ? {
27
- message: () => "expected array",
28
- pass: true
29
- } : {
30
- message: () => `expected array, but received ${typeof received}`,
31
- pass: false
32
- };
33
- },
34
- toBeOneOf(received, expected) {
35
- const pass = expected.includes(received);
36
- return pass ? {
37
- pass: true,
38
- message: () => `expected ${received} not to be one of ${JSON.stringify(expected)}`
39
- } : {
40
- pass: false,
41
- message: () => `expected ${received} to be one of ${JSON.stringify(expected)}`
42
- };
43
- },
44
- toBeNegative(received) {
45
- if (typeof received !== "number") {
46
- throw new TypeError(`Expected a number, but received ${typeof received}`);
47
- }
48
- const pass = received < 0;
49
- return pass ? {
50
- pass: true,
51
- message: () => `expected ${received} not to be negative`
52
- } : {
53
- pass: false,
54
- message: () => `expected ${received} to be negative`
55
- };
56
- },
57
- toBePositive(received) {
58
- if (typeof received !== "number") {
59
- throw new TypeError(`Expected a number, but received ${typeof received}`);
60
- }
61
- const pass = received > 0;
62
- return pass ? {
63
- pass: true,
64
- message: () => `expected ${received} not to be positive`
65
- } : {
66
- pass: false,
67
- message: () => `expected ${received} to be positive`
68
- };
69
- },
70
- toBeNumber: (received) => toBeType(received, "number"),
71
- toBeFunction: (received) => toBeType(received, "function"),
72
- toBeString: (received) => toBeType(received, "string"),
73
- toBeObject(received) {
74
- const pass = typeof received === "object" && !Array.isArray(received) && received !== null;
75
- return pass ? {
76
- message: () => `expected ${received} to be object`,
77
- pass: true
78
- } : {
79
- message: () => `expected ${received} to be an object but was ${Array.isArray(received) ? "array" : typeof received}`,
80
- pass: false
81
- };
82
- },
83
- toBeInteger(received) {
84
- if (typeof received !== "number") {
85
- throw new TypeError(`Expected a number, but received ${typeof received}`);
86
- }
87
- const pass = Number.isInteger(received);
88
- return pass ? {
89
- pass: true,
90
- message: () => `expected ${received} not to be an integer`
91
- } : {
92
- pass: false,
93
- message: () => `expected ${received} to be an integer`
94
- };
95
- },
96
- toBeFalse(received) {
97
- const pass = received === false;
98
- return pass ? {
99
- message: () => `expected ${received} to be false`,
100
- pass: true
101
- } : {
102
- message: () => `expected ${received} to be false but was not false`,
103
- pass: false
104
- };
105
- },
106
- toBeTrue(received) {
107
- const pass = received === true;
108
- return pass ? {
109
- message: () => `expected ${received} to be true`,
110
- pass: true
111
- } : {
112
- message: () => `expected ${received} to be true but was not true`,
113
- pass: false
114
- };
115
- },
116
- toIncludeAllMembers(received, expected) {
117
- if (!Array.isArray(received) || !Array.isArray(expected)) {
118
- return {
119
- pass: false,
120
- message: () => "Expected both received and expected values to be arrays."
121
- };
122
- }
123
- const missingMembers = expected.filter((item) => !received.includes(item));
124
- return missingMembers.length === 0 ? {
125
- pass: true,
126
- message: () => `Expected array not to include all members of ${JSON.stringify(expected)}, but it does.`
127
- } : {
128
- pass: false,
129
- message: () => `Expected array to include all members of ${JSON.stringify(expected)}. Missing members: ${JSON.stringify(
130
- missingMembers
131
- )}.`
132
- };
133
- },
134
- toContainAllKeys(received, expectedKeys) {
135
- if (typeof received !== "object" || received === null) {
136
- return {
137
- pass: false,
138
- message: () => `Expected ${JSON.stringify(received)} to be an object.`
139
- };
140
- }
141
- if (!Array.isArray(expectedKeys)) {
142
- return {
143
- pass: false,
144
- message: () => `Expected keys to be an array, but received ${JSON.stringify(expectedKeys)}.`
145
- };
146
- }
147
- const missingKeys = expectedKeys.filter((key) => !(key in received));
148
- return missingKeys.length === 0 ? {
149
- pass: true,
150
- message: () => `Expected object not to contain all keys ${JSON.stringify(expectedKeys)}, but it does.`
151
- } : {
152
- pass: false,
153
- message: () => `Expected object to contain all keys ${JSON.stringify(expectedKeys)}. Missing keys: ${JSON.stringify(
154
- missingKeys
155
- )}.`
156
- };
157
- },
158
- toContainValues(received, expectedValues) {
159
- if (typeof received !== "object" || received === null) {
160
- return {
161
- pass: false,
162
- message: () => `Expected ${JSON.stringify(received)} to be an object.`
163
- };
164
- }
165
- if (!Array.isArray(expectedValues)) {
166
- return {
167
- pass: false,
168
- message: () => `Expected values to be an array, but received ${JSON.stringify(expectedValues)}.`
169
- };
170
- }
171
- const objectValues = Object.values(received);
172
- const deepEqual = (a, b) => {
173
- if (a === b) return true;
174
- if (typeof a !== typeof b) return false;
175
- if (a && b && typeof a === "object") {
176
- const aKeys = Object.keys(a);
177
- const bKeys = Object.keys(b);
178
- if (aKeys.length !== bKeys.length) return false;
179
- return aKeys.every((key) => deepEqual(a[key], b[key]));
180
- }
181
- return false;
182
- };
183
- const missingValues = expectedValues.filter(
184
- (expectedValue) => !objectValues.some((value) => deepEqual(value, expectedValue))
185
- );
186
- return missingValues.length === 0 ? {
187
- pass: true,
188
- message: () => `Expected object not to contain all values ${JSON.stringify(expectedValues)}, but it does.`
189
- } : {
190
- pass: false,
191
- message: () => `Expected object to contain all values ${JSON.stringify(expectedValues)}. Missing values: ${JSON.stringify(
192
- missingValues
193
- )}.`
194
- };
195
- },
196
- toBeEmpty(received) {
197
- let isEmpty = false;
198
- if (Array.isArray(received) || typeof received === "string") {
199
- isEmpty = received.length === 0;
200
- } else if (received && typeof received === "object") {
201
- isEmpty = Object.keys(received).length === 0;
202
- } else if (received instanceof Map || received instanceof Set) {
203
- isEmpty = received.size === 0;
204
- } else {
205
- return {
206
- pass: false,
207
- message: () => `Expected value to be an empty array, string, object, Map, or Set, but received ${typeof received}.`
208
- };
209
- }
210
- return isEmpty ? {
211
- pass: true,
212
- message: () => "Expected value not to be empty, but it was."
213
- } : {
214
- pass: false,
215
- message: () => "Expected value to be empty, but it was not."
216
- };
217
- }
218
- };
219
4
  expect.extend(matchers);
220
- export {
221
- matchers
222
- };
223
5
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/customMatchers.ts"],"sourcesContent":["import { expect } from 'vitest'\n\ninterface ExpectationResult {\n actual?: unknown\n expected?: unknown\n message: () => string\n pass: boolean\n}\n\nfunction toBeType(received: unknown, expectedType: string): ExpectationResult {\n const pass = typeof received === expectedType && !Number.isNaN(received)\n return pass\n ? {\n message: () => `expected ${received} not to be a ${expectedType}`,\n pass: true,\n }\n : {\n message: () => `expected ${received} to be a ${expectedType}`,\n pass: false,\n }\n}\n\nexport const matchers = {\n toBeArrayOfSize(received: unknown, expectedSize: number): ExpectationResult {\n const pass = Array.isArray(received) && received.length === expectedSize\n return pass\n ? {\n message: () => `expected array not to have size ${expectedSize}, but received array of size ${received.length}`,\n pass: true,\n }\n : {\n message: () => Array.isArray(received)\n ? `expected array of size ${expectedSize}, but received array of size ${received.length}`\n : `expected array of size ${expectedSize}, but received a non-array`,\n pass: false,\n }\n },\n toBeArray(received: unknown): ExpectationResult {\n const pass = Array.isArray(received)\n return pass\n ? {\n message: () => 'expected array',\n pass: true,\n }\n : {\n message: () => `expected array, but received ${typeof received}`,\n pass: false,\n }\n },\n toBeOneOf(received: unknown, expected: unknown[]): ExpectationResult {\n const pass = expected.includes(received)\n return pass\n ? {\n pass: true,\n message: () =>\n `expected ${received} not to be one of ${JSON.stringify(expected)}`,\n }\n : {\n pass: false,\n message: () =>\n `expected ${received} to be one of ${JSON.stringify(expected)}`,\n }\n },\n toBeNegative(received: number): ExpectationResult {\n if (typeof received !== 'number') {\n throw new TypeError(`Expected a number, but received ${typeof received}`)\n }\n\n const pass = received < 0\n return pass\n ? {\n pass: true,\n message: () =>\n `expected ${received} not to be negative`,\n }\n : {\n pass: false,\n message: () =>\n `expected ${received} to be negative`,\n }\n },\n toBePositive(received: number): ExpectationResult {\n if (typeof received !== 'number') {\n throw new TypeError(`Expected a number, but received ${typeof received}`)\n }\n\n const pass = received > 0\n return pass\n ? {\n pass: true,\n message: () =>\n `expected ${received} not to be positive`,\n }\n : {\n pass: false,\n message: () =>\n `expected ${received} to be positive`,\n }\n },\n toBeNumber: (received: unknown) => toBeType(received, 'number'),\n toBeFunction: (received: unknown) => toBeType(received, 'function'),\n toBeString: (received: unknown) => toBeType(received, 'string'),\n toBeObject(received: unknown): ExpectationResult {\n const pass = typeof received === 'object' && !Array.isArray(received) && received !== null\n return pass\n ? {\n message: () => `expected ${received} to be object`,\n pass: true,\n }\n : {\n message: () => `expected ${received} to be an object but was ${Array.isArray(received) ? 'array' : typeof received}`,\n pass: false,\n }\n },\n toBeInteger(received: number): ExpectationResult {\n if (typeof received !== 'number') {\n throw new TypeError(`Expected a number, but received ${typeof received}`)\n }\n\n const pass = Number.isInteger(received)\n return pass\n ? {\n pass: true,\n message: () =>\n `expected ${received} not to be an integer`,\n }\n : {\n pass: false,\n message: () =>\n `expected ${received} to be an integer`,\n }\n },\n toBeFalse(received: unknown): ExpectationResult {\n const pass = received === false\n return pass\n ? {\n message: () => `expected ${received} to be false`,\n pass: true,\n }\n : {\n message: () => `expected ${received} to be false but was not false`,\n pass: false,\n }\n },\n toBeTrue(received: unknown): ExpectationResult {\n const pass = received === true\n return pass\n ? {\n message: () => `expected ${received} to be true`,\n pass: true,\n }\n : {\n message: () => `expected ${received} to be true but was not true`,\n pass: false,\n }\n },\n toIncludeAllMembers(received: unknown[], expected: unknown[]): ExpectationResult {\n if (!Array.isArray(received) || !Array.isArray(expected)) {\n return {\n pass: false,\n message: () => 'Expected both received and expected values to be arrays.',\n }\n }\n\n const missingMembers = expected.filter(item => !received.includes(item))\n\n return missingMembers.length === 0\n ? {\n pass: true,\n message: () =>\n `Expected array not to include all members of ${JSON.stringify(expected)}, but it does.`,\n }\n : {\n pass: false,\n message: () =>\n `Expected array to include all members of ${JSON.stringify(expected)}. Missing members: ${JSON.stringify(\n missingMembers,\n )}.`,\n }\n },\n toContainAllKeys(received: object, expectedKeys: string[]): ExpectationResult {\n if (typeof received !== 'object' || received === null) {\n return {\n pass: false,\n message: () => `Expected ${JSON.stringify(received)} to be an object.`,\n }\n }\n\n if (!Array.isArray(expectedKeys)) {\n return {\n pass: false,\n message: () => `Expected keys to be an array, but received ${JSON.stringify(expectedKeys)}.`,\n }\n }\n\n const missingKeys = expectedKeys.filter(key => !(key in received))\n\n return missingKeys.length === 0\n ? {\n pass: true,\n message: () =>\n `Expected object not to contain all keys ${JSON.stringify(expectedKeys)}, but it does.`,\n }\n : {\n pass: false,\n message: () =>\n `Expected object to contain all keys ${JSON.stringify(expectedKeys)}. Missing keys: ${JSON.stringify(\n missingKeys,\n )}.`,\n }\n },\n toContainValues(received: object, expectedValues: unknown[]): ExpectationResult {\n if (typeof received !== 'object' || received === null) {\n return {\n pass: false,\n message: () => `Expected ${JSON.stringify(received)} to be an object.`,\n }\n }\n\n if (!Array.isArray(expectedValues)) {\n return {\n pass: false,\n message: () => `Expected values to be an array, but received ${JSON.stringify(expectedValues)}.`,\n }\n }\n\n const objectValues = Object.values(received)\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const deepEqual = (a: any, b: any): boolean => {\n if (a === b) return true\n if (typeof a !== typeof b) return false\n if (a && b && typeof a === 'object') {\n const aKeys = Object.keys(a)\n const bKeys = Object.keys(b)\n if (aKeys.length !== bKeys.length) return false\n return aKeys.every(key => deepEqual(a[key], b[key]))\n }\n return false\n }\n\n const missingValues = expectedValues.filter(\n expectedValue => !objectValues.some(value => deepEqual(value, expectedValue)),\n )\n\n return missingValues.length === 0\n ? {\n pass: true,\n message: () =>\n `Expected object not to contain all values ${JSON.stringify(expectedValues)}, but it does.`,\n }\n : {\n pass: false,\n message: () =>\n `Expected object to contain all values ${JSON.stringify(expectedValues)}. Missing values: ${JSON.stringify(\n missingValues,\n )}.`,\n }\n },\n toBeEmpty(received: unknown): ExpectationResult {\n let isEmpty = false\n\n if (Array.isArray(received) || typeof received === 'string') {\n isEmpty = received.length === 0\n } else if (received && typeof received === 'object') {\n isEmpty = Object.keys(received).length === 0\n } else if (received instanceof Map || received instanceof Set) {\n isEmpty = received.size === 0\n } else {\n return {\n pass: false,\n message: () =>\n `Expected value to be an empty array, string, object, Map, or Set, but received ${typeof received}.`,\n }\n }\n\n return isEmpty\n ? {\n pass: true,\n message: () =>\n 'Expected value not to be empty, but it was.',\n }\n : {\n pass: false,\n message: () =>\n 'Expected value to be empty, but it was not.',\n }\n },\n}\n\nexpect.extend(matchers)\n"],"mappings":";AAAA,SAAS,cAAc;AASvB,SAAS,SAAS,UAAmB,cAAyC;AAC5E,QAAM,OAAO,OAAO,aAAa,gBAAgB,CAAC,OAAO,MAAM,QAAQ;AACvE,SAAO,OACH;AAAA,IACE,SAAS,MAAM,YAAY,QAAQ,gBAAgB,YAAY;AAAA,IAC/D,MAAM;AAAA,EACR,IACA;AAAA,IACE,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;AAAA,MACE,MAAM;AAAA,MACN,SAAS,MACP,yCAAyC,KAAK,UAAU,cAAc,CAAC,qBAAqB,KAAK;AAAA,QAC/F;AAAA,MACF,CAAC;AAAA,IACL;AAAA,EACN;AAAA,EACA,UAAU,UAAsC;AAC9C,QAAI,UAAU;AAEd,QAAI,MAAM,QAAQ,QAAQ,KAAK,OAAO,aAAa,UAAU;AAC3D,gBAAU,SAAS,WAAW;AAAA,IAChC,WAAW,YAAY,OAAO,aAAa,UAAU;AACnD,gBAAU,OAAO,KAAK,QAAQ,EAAE,WAAW;AAAA,IAC7C,WAAW,oBAAoB,OAAO,oBAAoB,KAAK;AAC7D,gBAAU,SAAS,SAAS;AAAA,IAC9B,OAAO;AACL,aAAO;AAAA,QACL,MAAM;AAAA,QACN,SAAS,MACP,kFAAkF,OAAO,QAAQ;AAAA,MACrG;AAAA,IACF;AAEA,WAAO,UACH;AAAA,MACE,MAAM;AAAA,MACN,SAAS,MACP;AAAA,IACJ,IACA;AAAA,MACE,MAAM;AAAA,MACN,SAAS,MACP;AAAA,IACJ;AAAA,EACN;AACF;AAEA,OAAO,OAAO,QAAQ;","names":[]}
1
+ {"version":3,"sources":["../../src/customMatchers.ts"],"sourcesContent":["import { matchers } from '@xylabs/vitest-matchers'\nimport { expect } from 'vitest'\n\nexpect.extend(matchers)\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,cAAc;AAEvB,OAAO,OAAO,QAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/vitest-extended",
3
- "version": "4.4.8",
3
+ "version": "4.4.10",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "log",
@@ -37,11 +37,9 @@
37
37
  },
38
38
  "module": "./dist/neutral/index.mjs",
39
39
  "types": "./types.d.ts",
40
- "workspaces": [
41
- "packages/**/*"
42
- ],
43
40
  "dependencies": {
44
- "vitest": "^2.1.5"
41
+ "@xylabs/vitest-matchers": "^4.4.10",
42
+ "vitest": "^2.1.6"
45
43
  },
46
44
  "devDependencies": {
47
45
  "@xylabs/ts-scripts-yarn3": "^4.2.4",
@@ -1,291 +1,4 @@
1
+ import { matchers } from '@xylabs/vitest-matchers'
1
2
  import { expect } from 'vitest'
2
3
 
3
- interface ExpectationResult {
4
- actual?: unknown
5
- expected?: unknown
6
- message: () => string
7
- pass: boolean
8
- }
9
-
10
- function toBeType(received: unknown, expectedType: string): ExpectationResult {
11
- const pass = typeof received === expectedType && !Number.isNaN(received)
12
- return pass
13
- ? {
14
- message: () => `expected ${received} not to be a ${expectedType}`,
15
- pass: true,
16
- }
17
- : {
18
- message: () => `expected ${received} to be a ${expectedType}`,
19
- pass: false,
20
- }
21
- }
22
-
23
- export const matchers = {
24
- toBeArrayOfSize(received: unknown, expectedSize: number): ExpectationResult {
25
- const pass = Array.isArray(received) && received.length === expectedSize
26
- return pass
27
- ? {
28
- message: () => `expected array not to have size ${expectedSize}, but received array of size ${received.length}`,
29
- pass: true,
30
- }
31
- : {
32
- message: () => Array.isArray(received)
33
- ? `expected array of size ${expectedSize}, but received array of size ${received.length}`
34
- : `expected array of size ${expectedSize}, but received a non-array`,
35
- pass: false,
36
- }
37
- },
38
- toBeArray(received: unknown): ExpectationResult {
39
- const pass = Array.isArray(received)
40
- return pass
41
- ? {
42
- message: () => 'expected array',
43
- pass: true,
44
- }
45
- : {
46
- message: () => `expected array, but received ${typeof received}`,
47
- pass: false,
48
- }
49
- },
50
- toBeOneOf(received: unknown, expected: unknown[]): ExpectationResult {
51
- const pass = expected.includes(received)
52
- return pass
53
- ? {
54
- pass: true,
55
- message: () =>
56
- `expected ${received} not to be one of ${JSON.stringify(expected)}`,
57
- }
58
- : {
59
- pass: false,
60
- message: () =>
61
- `expected ${received} to be one of ${JSON.stringify(expected)}`,
62
- }
63
- },
64
- toBeNegative(received: number): ExpectationResult {
65
- if (typeof received !== 'number') {
66
- throw new TypeError(`Expected a number, but received ${typeof received}`)
67
- }
68
-
69
- const pass = received < 0
70
- return pass
71
- ? {
72
- pass: true,
73
- message: () =>
74
- `expected ${received} not to be negative`,
75
- }
76
- : {
77
- pass: false,
78
- message: () =>
79
- `expected ${received} to be negative`,
80
- }
81
- },
82
- toBePositive(received: number): ExpectationResult {
83
- if (typeof received !== 'number') {
84
- throw new TypeError(`Expected a number, but received ${typeof received}`)
85
- }
86
-
87
- const pass = received > 0
88
- return pass
89
- ? {
90
- pass: true,
91
- message: () =>
92
- `expected ${received} not to be positive`,
93
- }
94
- : {
95
- pass: false,
96
- message: () =>
97
- `expected ${received} to be positive`,
98
- }
99
- },
100
- toBeNumber: (received: unknown) => toBeType(received, 'number'),
101
- toBeFunction: (received: unknown) => toBeType(received, 'function'),
102
- toBeString: (received: unknown) => toBeType(received, 'string'),
103
- toBeObject(received: unknown): ExpectationResult {
104
- const pass = typeof received === 'object' && !Array.isArray(received) && received !== null
105
- return pass
106
- ? {
107
- message: () => `expected ${received} to be object`,
108
- pass: true,
109
- }
110
- : {
111
- message: () => `expected ${received} to be an object but was ${Array.isArray(received) ? 'array' : typeof received}`,
112
- pass: false,
113
- }
114
- },
115
- toBeInteger(received: number): ExpectationResult {
116
- if (typeof received !== 'number') {
117
- throw new TypeError(`Expected a number, but received ${typeof received}`)
118
- }
119
-
120
- const pass = Number.isInteger(received)
121
- return pass
122
- ? {
123
- pass: true,
124
- message: () =>
125
- `expected ${received} not to be an integer`,
126
- }
127
- : {
128
- pass: false,
129
- message: () =>
130
- `expected ${received} to be an integer`,
131
- }
132
- },
133
- toBeFalse(received: unknown): ExpectationResult {
134
- const pass = received === false
135
- return pass
136
- ? {
137
- message: () => `expected ${received} to be false`,
138
- pass: true,
139
- }
140
- : {
141
- message: () => `expected ${received} to be false but was not false`,
142
- pass: false,
143
- }
144
- },
145
- toBeTrue(received: unknown): ExpectationResult {
146
- const pass = received === true
147
- return pass
148
- ? {
149
- message: () => `expected ${received} to be true`,
150
- pass: true,
151
- }
152
- : {
153
- message: () => `expected ${received} to be true but was not true`,
154
- pass: false,
155
- }
156
- },
157
- toIncludeAllMembers(received: unknown[], expected: unknown[]): ExpectationResult {
158
- if (!Array.isArray(received) || !Array.isArray(expected)) {
159
- return {
160
- pass: false,
161
- message: () => 'Expected both received and expected values to be arrays.',
162
- }
163
- }
164
-
165
- const missingMembers = expected.filter(item => !received.includes(item))
166
-
167
- return missingMembers.length === 0
168
- ? {
169
- pass: true,
170
- message: () =>
171
- `Expected array not to include all members of ${JSON.stringify(expected)}, but it does.`,
172
- }
173
- : {
174
- pass: false,
175
- message: () =>
176
- `Expected array to include all members of ${JSON.stringify(expected)}. Missing members: ${JSON.stringify(
177
- missingMembers,
178
- )}.`,
179
- }
180
- },
181
- toContainAllKeys(received: object, expectedKeys: string[]): ExpectationResult {
182
- if (typeof received !== 'object' || received === null) {
183
- return {
184
- pass: false,
185
- message: () => `Expected ${JSON.stringify(received)} to be an object.`,
186
- }
187
- }
188
-
189
- if (!Array.isArray(expectedKeys)) {
190
- return {
191
- pass: false,
192
- message: () => `Expected keys to be an array, but received ${JSON.stringify(expectedKeys)}.`,
193
- }
194
- }
195
-
196
- const missingKeys = expectedKeys.filter(key => !(key in received))
197
-
198
- return missingKeys.length === 0
199
- ? {
200
- pass: true,
201
- message: () =>
202
- `Expected object not to contain all keys ${JSON.stringify(expectedKeys)}, but it does.`,
203
- }
204
- : {
205
- pass: false,
206
- message: () =>
207
- `Expected object to contain all keys ${JSON.stringify(expectedKeys)}. Missing keys: ${JSON.stringify(
208
- missingKeys,
209
- )}.`,
210
- }
211
- },
212
- toContainValues(received: object, expectedValues: unknown[]): ExpectationResult {
213
- if (typeof received !== 'object' || received === null) {
214
- return {
215
- pass: false,
216
- message: () => `Expected ${JSON.stringify(received)} to be an object.`,
217
- }
218
- }
219
-
220
- if (!Array.isArray(expectedValues)) {
221
- return {
222
- pass: false,
223
- message: () => `Expected values to be an array, but received ${JSON.stringify(expectedValues)}.`,
224
- }
225
- }
226
-
227
- const objectValues = Object.values(received)
228
-
229
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
230
- const deepEqual = (a: any, b: any): boolean => {
231
- if (a === b) return true
232
- if (typeof a !== typeof b) return false
233
- if (a && b && typeof a === 'object') {
234
- const aKeys = Object.keys(a)
235
- const bKeys = Object.keys(b)
236
- if (aKeys.length !== bKeys.length) return false
237
- return aKeys.every(key => deepEqual(a[key], b[key]))
238
- }
239
- return false
240
- }
241
-
242
- const missingValues = expectedValues.filter(
243
- expectedValue => !objectValues.some(value => deepEqual(value, expectedValue)),
244
- )
245
-
246
- return missingValues.length === 0
247
- ? {
248
- pass: true,
249
- message: () =>
250
- `Expected object not to contain all values ${JSON.stringify(expectedValues)}, but it does.`,
251
- }
252
- : {
253
- pass: false,
254
- message: () =>
255
- `Expected object to contain all values ${JSON.stringify(expectedValues)}. Missing values: ${JSON.stringify(
256
- missingValues,
257
- )}.`,
258
- }
259
- },
260
- toBeEmpty(received: unknown): ExpectationResult {
261
- let isEmpty = false
262
-
263
- if (Array.isArray(received) || typeof received === 'string') {
264
- isEmpty = received.length === 0
265
- } else if (received && typeof received === 'object') {
266
- isEmpty = Object.keys(received).length === 0
267
- } else if (received instanceof Map || received instanceof Set) {
268
- isEmpty = received.size === 0
269
- } else {
270
- return {
271
- pass: false,
272
- message: () =>
273
- `Expected value to be an empty array, string, object, Map, or Set, but received ${typeof received}.`,
274
- }
275
- }
276
-
277
- return isEmpty
278
- ? {
279
- pass: true,
280
- message: () =>
281
- 'Expected value not to be empty, but it was.',
282
- }
283
- : {
284
- pass: false,
285
- message: () =>
286
- 'Expected value to be empty, but it was not.',
287
- }
288
- },
289
- }
290
-
291
4
  expect.extend(matchers)