@hyperfixi/testing-framework 2.0.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/dist/assertions-BImuwZsB.d.mts +458 -0
- package/dist/assertions-BImuwZsB.d.ts +458 -0
- package/dist/assertions.d.mts +1 -0
- package/dist/assertions.d.ts +1 -0
- package/dist/assertions.js +625 -0
- package/dist/assertions.js.map +1 -0
- package/dist/assertions.mjs +621 -0
- package/dist/assertions.mjs.map +1 -0
- package/dist/index.d.mts +246 -0
- package/dist/index.d.ts +246 -0
- package/dist/index.js +1465 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1435 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +121 -0
- package/src/assertions.test.ts +490 -0
- package/src/assertions.ts +779 -0
- package/src/index.test.ts +490 -0
- package/src/index.ts +601 -0
- package/src/jsdom.d.ts +7 -0
- package/src/multilingual/README.md +295 -0
- package/src/multilingual/bundle-builder.ts +345 -0
- package/src/multilingual/cli.ts +224 -0
- package/src/multilingual/index.ts +68 -0
- package/src/multilingual/orchestrator.ts +275 -0
- package/src/multilingual/pattern-loader.ts +176 -0
- package/src/multilingual/reporters/console-reporter.ts +294 -0
- package/src/multilingual/reporters/json-reporter.ts +99 -0
- package/src/multilingual/reporters/regression-reporter.ts +263 -0
- package/src/multilingual/tools/analyze-failures.ts +326 -0
- package/src/multilingual/types.ts +268 -0
- package/src/multilingual/validators/parse-diagnostics.ts +337 -0
- package/src/multilingual/validators/parse-validator.ts +193 -0
- package/src/multilingual/validators/size-validator.ts +187 -0
- package/src/runner.test.ts +813 -0
- package/src/runner.ts +639 -0
- package/src/types.ts +505 -0
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for Assertion Library
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
6
|
+
import { createExpectAPI, createAssertAPI, AssertionError } from './assertions';
|
|
7
|
+
|
|
8
|
+
describe('Assertions Library', () => {
|
|
9
|
+
describe('createExpectAPI', () => {
|
|
10
|
+
const expectFn = createExpectAPI();
|
|
11
|
+
|
|
12
|
+
describe('toBe', () => {
|
|
13
|
+
it('should pass for same values', () => {
|
|
14
|
+
expect(() => expectFn(5).toBe(5)).not.toThrow();
|
|
15
|
+
expect(() => expectFn('hello').toBe('hello')).not.toThrow();
|
|
16
|
+
expect(() => expectFn(null).toBe(null)).not.toThrow();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should fail for different values', () => {
|
|
20
|
+
expect(() => expectFn(5).toBe(6)).toThrow(AssertionError);
|
|
21
|
+
expect(() => expectFn('hello').toBe('world')).toThrow(AssertionError);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should handle reference equality', () => {
|
|
25
|
+
const obj = { a: 1 };
|
|
26
|
+
expect(() => expectFn(obj).toBe(obj)).not.toThrow();
|
|
27
|
+
expect(() => expectFn({ a: 1 }).toBe({ a: 1 })).toThrow(AssertionError);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('toEqual', () => {
|
|
32
|
+
it('should pass for deeply equal objects', () => {
|
|
33
|
+
expect(() => expectFn({ a: 1, b: 2 }).toEqual({ a: 1, b: 2 })).not.toThrow();
|
|
34
|
+
expect(() => expectFn([1, 2, 3]).toEqual([1, 2, 3])).not.toThrow();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should fail for non-equal objects', () => {
|
|
38
|
+
expect(() => expectFn({ a: 1 }).toEqual({ a: 2 })).toThrow(AssertionError);
|
|
39
|
+
expect(() => expectFn([1, 2]).toEqual([1, 2, 3])).toThrow(AssertionError);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should handle nested objects', () => {
|
|
43
|
+
expect(() => expectFn({ a: { b: 1 } }).toEqual({ a: { b: 1 } })).not.toThrow();
|
|
44
|
+
expect(() => expectFn({ a: { b: 1 } }).toEqual({ a: { b: 2 } })).toThrow(AssertionError);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should handle Date objects', () => {
|
|
48
|
+
const date = new Date('2024-01-01');
|
|
49
|
+
expect(() => expectFn(date).toEqual(new Date('2024-01-01'))).not.toThrow();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should handle RegExp objects', () => {
|
|
53
|
+
expect(() => expectFn(/abc/).toEqual(/abc/)).not.toThrow();
|
|
54
|
+
expect(() => expectFn(/abc/i).toEqual(/abc/)).toThrow(AssertionError);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('toBeTruthy', () => {
|
|
59
|
+
it('should pass for truthy values', () => {
|
|
60
|
+
expect(() => expectFn(true).toBeTruthy()).not.toThrow();
|
|
61
|
+
expect(() => expectFn(1).toBeTruthy()).not.toThrow();
|
|
62
|
+
expect(() => expectFn('hello').toBeTruthy()).not.toThrow();
|
|
63
|
+
expect(() => expectFn({}).toBeTruthy()).not.toThrow();
|
|
64
|
+
expect(() => expectFn([]).toBeTruthy()).not.toThrow();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should fail for falsy values', () => {
|
|
68
|
+
expect(() => expectFn(false).toBeTruthy()).toThrow(AssertionError);
|
|
69
|
+
expect(() => expectFn(0).toBeTruthy()).toThrow(AssertionError);
|
|
70
|
+
expect(() => expectFn('').toBeTruthy()).toThrow(AssertionError);
|
|
71
|
+
expect(() => expectFn(null).toBeTruthy()).toThrow(AssertionError);
|
|
72
|
+
expect(() => expectFn(undefined).toBeTruthy()).toThrow(AssertionError);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('toBeFalsy', () => {
|
|
77
|
+
it('should pass for falsy values', () => {
|
|
78
|
+
expect(() => expectFn(false).toBeFalsy()).not.toThrow();
|
|
79
|
+
expect(() => expectFn(0).toBeFalsy()).not.toThrow();
|
|
80
|
+
expect(() => expectFn('').toBeFalsy()).not.toThrow();
|
|
81
|
+
expect(() => expectFn(null).toBeFalsy()).not.toThrow();
|
|
82
|
+
expect(() => expectFn(undefined).toBeFalsy()).not.toThrow();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('should fail for truthy values', () => {
|
|
86
|
+
expect(() => expectFn(true).toBeFalsy()).toThrow(AssertionError);
|
|
87
|
+
expect(() => expectFn(1).toBeFalsy()).toThrow(AssertionError);
|
|
88
|
+
expect(() => expectFn('hello').toBeFalsy()).toThrow(AssertionError);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('toBeNull', () => {
|
|
93
|
+
it('should pass for null', () => {
|
|
94
|
+
expect(() => expectFn(null).toBeNull()).not.toThrow();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('should fail for non-null values', () => {
|
|
98
|
+
expect(() => expectFn(undefined).toBeNull()).toThrow(AssertionError);
|
|
99
|
+
expect(() => expectFn(0).toBeNull()).toThrow(AssertionError);
|
|
100
|
+
expect(() => expectFn('').toBeNull()).toThrow(AssertionError);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe('toBeUndefined', () => {
|
|
105
|
+
it('should pass for undefined', () => {
|
|
106
|
+
expect(() => expectFn(undefined).toBeUndefined()).not.toThrow();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should fail for defined values', () => {
|
|
110
|
+
expect(() => expectFn(null).toBeUndefined()).toThrow(AssertionError);
|
|
111
|
+
expect(() => expectFn(0).toBeUndefined()).toThrow(AssertionError);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe('toBeDefined', () => {
|
|
116
|
+
it('should pass for defined values', () => {
|
|
117
|
+
expect(() => expectFn(null).toBeDefined()).not.toThrow();
|
|
118
|
+
expect(() => expectFn(0).toBeDefined()).not.toThrow();
|
|
119
|
+
expect(() => expectFn('').toBeDefined()).not.toThrow();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('should fail for undefined', () => {
|
|
123
|
+
expect(() => expectFn(undefined).toBeDefined()).toThrow(AssertionError);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('toBeNaN', () => {
|
|
128
|
+
it('should pass for NaN', () => {
|
|
129
|
+
expect(() => expectFn(NaN).toBeNaN()).not.toThrow();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should fail for non-NaN values', () => {
|
|
133
|
+
expect(() => expectFn(123).toBeNaN()).toThrow(AssertionError);
|
|
134
|
+
expect(() => expectFn('not a number').toBeNaN()).toThrow(AssertionError);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe('toBeInstanceOf', () => {
|
|
139
|
+
it('should pass for correct instances', () => {
|
|
140
|
+
expect(() => expectFn(new Date()).toBeInstanceOf(Date)).not.toThrow();
|
|
141
|
+
expect(() => expectFn([]).toBeInstanceOf(Array)).not.toThrow();
|
|
142
|
+
expect(() => expectFn(new Error()).toBeInstanceOf(Error)).not.toThrow();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('should fail for incorrect instances', () => {
|
|
146
|
+
expect(() => expectFn({}).toBeInstanceOf(Array)).toThrow(AssertionError);
|
|
147
|
+
expect(() => expectFn('').toBeInstanceOf(Number)).toThrow(AssertionError);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe('toBeCloseTo', () => {
|
|
152
|
+
it('should pass for close numbers', () => {
|
|
153
|
+
expect(() => expectFn(0.1 + 0.2).toBeCloseTo(0.3)).not.toThrow();
|
|
154
|
+
expect(() => expectFn(Math.PI).toBeCloseTo(3.14, 2)).not.toThrow();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('should fail for distant numbers', () => {
|
|
158
|
+
expect(() => expectFn(0.5).toBeCloseTo(0.3)).toThrow(AssertionError);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('should throw for non-numbers', () => {
|
|
162
|
+
expect(() => expectFn('hello').toBeCloseTo(5)).toThrow(AssertionError);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe('toMatch', () => {
|
|
167
|
+
it('should pass for matching strings', () => {
|
|
168
|
+
expect(() => expectFn('hello world').toMatch('world')).not.toThrow();
|
|
169
|
+
expect(() => expectFn('hello world').toMatch(/world/)).not.toThrow();
|
|
170
|
+
expect(() => expectFn('Hello World').toMatch(/hello/i)).not.toThrow();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('should fail for non-matching strings', () => {
|
|
174
|
+
expect(() => expectFn('hello').toMatch('world')).toThrow(AssertionError);
|
|
175
|
+
expect(() => expectFn('hello').toMatch(/World/)).toThrow(AssertionError);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('should throw for non-strings', () => {
|
|
179
|
+
expect(() => expectFn(123).toMatch('123')).toThrow(AssertionError);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
describe('toContain', () => {
|
|
184
|
+
it('should pass for string containing substring', () => {
|
|
185
|
+
expect(() => expectFn('hello world').toContain('world')).not.toThrow();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('should pass for array containing item', () => {
|
|
189
|
+
expect(() => expectFn([1, 2, 3]).toContain(2)).not.toThrow();
|
|
190
|
+
expect(() => expectFn(['a', 'b', 'c']).toContain('b')).not.toThrow();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('should fail for non-containing values', () => {
|
|
194
|
+
expect(() => expectFn('hello').toContain('world')).toThrow(AssertionError);
|
|
195
|
+
expect(() => expectFn([1, 2, 3]).toContain(4)).toThrow(AssertionError);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe('toHaveLength', () => {
|
|
200
|
+
it('should pass for correct length', () => {
|
|
201
|
+
expect(() => expectFn('hello').toHaveLength(5)).not.toThrow();
|
|
202
|
+
expect(() => expectFn([1, 2, 3]).toHaveLength(3)).not.toThrow();
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('should fail for incorrect length', () => {
|
|
206
|
+
expect(() => expectFn('hello').toHaveLength(10)).toThrow(AssertionError);
|
|
207
|
+
expect(() => expectFn([1, 2]).toHaveLength(5)).toThrow(AssertionError);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('should throw for values without length', () => {
|
|
211
|
+
expect(() => expectFn(123).toHaveLength(3)).toThrow(AssertionError);
|
|
212
|
+
expect(() => expectFn(null).toHaveLength(0)).toThrow(AssertionError);
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
describe('toContainEqual', () => {
|
|
217
|
+
it('should pass for array containing equal object', () => {
|
|
218
|
+
expect(() => expectFn([{ a: 1 }, { b: 2 }]).toContainEqual({ a: 1 })).not.toThrow();
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('should fail for array not containing equal object', () => {
|
|
222
|
+
expect(() => expectFn([{ a: 1 }]).toContainEqual({ a: 2 })).toThrow(AssertionError);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('should throw for non-arrays', () => {
|
|
226
|
+
expect(() => expectFn('hello').toContainEqual('h')).toThrow(AssertionError);
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
describe('toHaveProperty', () => {
|
|
231
|
+
it('should pass for existing property', () => {
|
|
232
|
+
expect(() => expectFn({ a: 1 }).toHaveProperty('a')).not.toThrow();
|
|
233
|
+
expect(() => expectFn({ a: { b: 2 } }).toHaveProperty('a.b')).not.toThrow();
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('should pass for property with specific value', () => {
|
|
237
|
+
expect(() => expectFn({ a: 1 }).toHaveProperty('a', 1)).not.toThrow();
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it('should fail for non-existing property', () => {
|
|
241
|
+
expect(() => expectFn({ a: 1 }).toHaveProperty('b')).toThrow(AssertionError);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('should fail for property with wrong value', () => {
|
|
245
|
+
expect(() => expectFn({ a: 1 }).toHaveProperty('a', 2)).toThrow(AssertionError);
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
describe('toMatchObject', () => {
|
|
250
|
+
it('should pass for matching partial object', () => {
|
|
251
|
+
expect(() => expectFn({ a: 1, b: 2, c: 3 }).toMatchObject({ a: 1, b: 2 })).not.toThrow();
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it('should fail for non-matching object', () => {
|
|
255
|
+
expect(() => expectFn({ a: 1 }).toMatchObject({ a: 2 })).toThrow(AssertionError);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('should throw for non-objects', () => {
|
|
259
|
+
expect(() => expectFn('hello').toMatchObject({ length: 5 })).toThrow(AssertionError);
|
|
260
|
+
expect(() => expectFn(null).toMatchObject({})).toThrow(AssertionError);
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
describe('not modifier', () => {
|
|
265
|
+
it('should invert toBe', () => {
|
|
266
|
+
expect(() => expectFn(5).not.toBe(6)).not.toThrow();
|
|
267
|
+
expect(() => expectFn(5).not.toBe(5)).toThrow(AssertionError);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('should invert toEqual', () => {
|
|
271
|
+
expect(() => expectFn({ a: 1 }).not.toEqual({ a: 2 })).not.toThrow();
|
|
272
|
+
expect(() => expectFn({ a: 1 }).not.toEqual({ a: 1 })).toThrow(AssertionError);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it('should invert toBeTruthy', () => {
|
|
276
|
+
expect(() => expectFn(false).not.toBeTruthy()).not.toThrow();
|
|
277
|
+
expect(() => expectFn(true).not.toBeTruthy()).toThrow(AssertionError);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it('should invert toContain', () => {
|
|
281
|
+
expect(() => expectFn([1, 2, 3]).not.toContain(5)).not.toThrow();
|
|
282
|
+
expect(() => expectFn([1, 2, 3]).not.toContain(2)).toThrow(AssertionError);
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
describe('createAssertAPI', () => {
|
|
288
|
+
const assert = createAssertAPI();
|
|
289
|
+
|
|
290
|
+
describe('ok', () => {
|
|
291
|
+
it('should pass for truthy values', () => {
|
|
292
|
+
expect(() => assert.ok(true)).not.toThrow();
|
|
293
|
+
expect(() => assert.ok(1)).not.toThrow();
|
|
294
|
+
expect(() => assert.ok('hello')).not.toThrow();
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it('should fail for falsy values', () => {
|
|
298
|
+
expect(() => assert.ok(false)).toThrow(AssertionError);
|
|
299
|
+
expect(() => assert.ok(0)).toThrow(AssertionError);
|
|
300
|
+
expect(() => assert.ok('')).toThrow(AssertionError);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it('should use custom message', () => {
|
|
304
|
+
expect(() => assert.ok(false, 'Custom message')).toThrow('Custom message');
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
describe('equal', () => {
|
|
309
|
+
it('should pass for loosely equal values', () => {
|
|
310
|
+
expect(() => assert.equal(1, 1)).not.toThrow();
|
|
311
|
+
expect(() => assert.equal('1', 1)).not.toThrow();
|
|
312
|
+
expect(() => assert.equal(null, undefined)).not.toThrow();
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it('should fail for non-equal values', () => {
|
|
316
|
+
expect(() => assert.equal(1, 2)).toThrow(AssertionError);
|
|
317
|
+
expect(() => assert.equal('hello', 'world')).toThrow(AssertionError);
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
describe('strictEqual', () => {
|
|
322
|
+
it('should pass for strictly equal values', () => {
|
|
323
|
+
expect(() => assert.strictEqual(1, 1)).not.toThrow();
|
|
324
|
+
expect(() => assert.strictEqual('hello', 'hello')).not.toThrow();
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it('should fail for loosely equal but not strictly equal', () => {
|
|
328
|
+
expect(() => assert.strictEqual('1', 1)).toThrow(AssertionError);
|
|
329
|
+
expect(() => assert.strictEqual(null, undefined)).toThrow(AssertionError);
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
describe('notEqual', () => {
|
|
334
|
+
it('should pass for non-equal values', () => {
|
|
335
|
+
expect(() => assert.notEqual(1, 2)).not.toThrow();
|
|
336
|
+
expect(() => assert.notEqual('hello', 'world')).not.toThrow();
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it('should fail for equal values', () => {
|
|
340
|
+
expect(() => assert.notEqual(1, 1)).toThrow(AssertionError);
|
|
341
|
+
expect(() => assert.notEqual('1', 1)).toThrow(AssertionError);
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
describe('notStrictEqual', () => {
|
|
346
|
+
it('should pass for loosely equal but not strictly equal', () => {
|
|
347
|
+
expect(() => assert.notStrictEqual('1', 1)).not.toThrow();
|
|
348
|
+
expect(() => assert.notStrictEqual(null, undefined)).not.toThrow();
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it('should fail for strictly equal values', () => {
|
|
352
|
+
expect(() => assert.notStrictEqual(1, 1)).toThrow(AssertionError);
|
|
353
|
+
expect(() => assert.notStrictEqual('hello', 'hello')).toThrow(AssertionError);
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
describe('throws', () => {
|
|
358
|
+
it('should pass when function throws', () => {
|
|
359
|
+
expect(() =>
|
|
360
|
+
assert.throws(() => {
|
|
361
|
+
throw new Error('test');
|
|
362
|
+
})
|
|
363
|
+
).not.toThrow();
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it('should fail when function does not throw', () => {
|
|
367
|
+
expect(() => assert.throws(() => {})).toThrow(AssertionError);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it('should match error message', () => {
|
|
371
|
+
expect(() =>
|
|
372
|
+
assert.throws(() => {
|
|
373
|
+
throw new Error('test');
|
|
374
|
+
}, 'test')
|
|
375
|
+
).not.toThrow();
|
|
376
|
+
expect(() =>
|
|
377
|
+
assert.throws(() => {
|
|
378
|
+
throw new Error('test');
|
|
379
|
+
}, 'other')
|
|
380
|
+
).toThrow(AssertionError);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it('should match error type', () => {
|
|
384
|
+
expect(() =>
|
|
385
|
+
assert.throws(() => {
|
|
386
|
+
throw new TypeError('test');
|
|
387
|
+
}, TypeError)
|
|
388
|
+
).not.toThrow();
|
|
389
|
+
expect(() =>
|
|
390
|
+
assert.throws(() => {
|
|
391
|
+
throw new Error('test');
|
|
392
|
+
}, TypeError)
|
|
393
|
+
).toThrow(AssertionError);
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it('should match error regex', () => {
|
|
397
|
+
expect(() =>
|
|
398
|
+
assert.throws(() => {
|
|
399
|
+
throw new Error('test error');
|
|
400
|
+
}, /test/)
|
|
401
|
+
).not.toThrow();
|
|
402
|
+
expect(() =>
|
|
403
|
+
assert.throws(() => {
|
|
404
|
+
throw new Error('test error');
|
|
405
|
+
}, /other/)
|
|
406
|
+
).toThrow(AssertionError);
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
describe('doesNotThrow', () => {
|
|
411
|
+
it('should pass when function does not throw', () => {
|
|
412
|
+
expect(() => assert.doesNotThrow(() => {})).not.toThrow();
|
|
413
|
+
expect(() => assert.doesNotThrow(() => 123)).not.toThrow();
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
it('should fail when function throws', () => {
|
|
417
|
+
expect(() =>
|
|
418
|
+
assert.doesNotThrow(() => {
|
|
419
|
+
throw new Error('test');
|
|
420
|
+
})
|
|
421
|
+
).toThrow(AssertionError);
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
describe('ifError', () => {
|
|
426
|
+
it('should pass for falsy values', () => {
|
|
427
|
+
expect(() => assert.ifError(null)).not.toThrow();
|
|
428
|
+
expect(() => assert.ifError(undefined)).not.toThrow();
|
|
429
|
+
expect(() => assert.ifError(false)).not.toThrow();
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
it('should throw the value for truthy values', () => {
|
|
433
|
+
const error = new Error('test');
|
|
434
|
+
expect(() => assert.ifError(error)).toThrow(error);
|
|
435
|
+
expect(() => assert.ifError('error string')).toThrow('error string');
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
describe('rejects', () => {
|
|
440
|
+
it('should pass when promise rejects', async () => {
|
|
441
|
+
await expect(assert.rejects(Promise.reject(new Error('test')))).resolves.toBeUndefined();
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
it('should fail when promise resolves', async () => {
|
|
445
|
+
await expect(assert.rejects(Promise.resolve())).rejects.toThrow(AssertionError);
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
it('should match error message', async () => {
|
|
449
|
+
await expect(
|
|
450
|
+
assert.rejects(Promise.reject(new Error('test')), 'test')
|
|
451
|
+
).resolves.toBeUndefined();
|
|
452
|
+
await expect(assert.rejects(Promise.reject(new Error('test')), 'other')).rejects.toThrow(
|
|
453
|
+
AssertionError
|
|
454
|
+
);
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
describe('doesNotReject', () => {
|
|
459
|
+
it('should pass when promise resolves', async () => {
|
|
460
|
+
await expect(assert.doesNotReject(Promise.resolve())).resolves.toBeUndefined();
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
it('should fail when promise rejects', async () => {
|
|
464
|
+
await expect(assert.doesNotReject(Promise.reject(new Error('test')))).rejects.toThrow(
|
|
465
|
+
AssertionError
|
|
466
|
+
);
|
|
467
|
+
});
|
|
468
|
+
});
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
describe('AssertionError', () => {
|
|
472
|
+
it('should be an instance of Error', () => {
|
|
473
|
+
const error = new AssertionError('test');
|
|
474
|
+
expect(error).toBeInstanceOf(Error);
|
|
475
|
+
expect(error).toBeInstanceOf(AssertionError);
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
it('should have correct name', () => {
|
|
479
|
+
const error = new AssertionError('test');
|
|
480
|
+
expect(error.name).toBe('AssertionError');
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
it('should store expected and actual values', () => {
|
|
484
|
+
const error = new AssertionError('test', 'expected', 'actual', 'toBe');
|
|
485
|
+
expect(error.expected).toBe('expected');
|
|
486
|
+
expect(error.actual).toBe('actual');
|
|
487
|
+
expect(error.operator).toBe('toBe');
|
|
488
|
+
});
|
|
489
|
+
});
|
|
490
|
+
});
|