@as-pect/assembly 6.0.0 → 7.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/README.md +34 -34
- package/assembly/index.ts +24 -24
- package/assembly/internal/Actual.ts +20 -20
- package/assembly/internal/Expectation.ts +544 -481
- package/assembly/internal/Expected.ts +55 -55
- package/assembly/internal/Reflect.ts +698 -662
- package/assembly/internal/ReflectedValueType.ts +17 -17
- package/assembly/internal/Test.ts +81 -81
- package/assembly/internal/assert.ts +3 -3
- package/assembly/internal/call.ts +3 -3
- package/assembly/internal/comparison/toIncludeComparison.ts +67 -62
- package/assembly/internal/comparison/toIncludeEqualComparison.ts +91 -78
- package/assembly/internal/log.ts +19 -18
- package/assembly/internal/noOp.ts +3 -2
- package/package.json +17 -10
- package/types/as-pect.d.ts +733 -733
- package/types/as-pect.portable.d.ts +389 -389
- package/types/env.d.ts +1 -1
|
@@ -1,389 +1,389 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This function creates a test group in the test loader.
|
|
3
|
-
*
|
|
4
|
-
* @param {string} description - This is the name of the test group.
|
|
5
|
-
* @param {() => void} callback - A function that contains all of the closures for this test group.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* describe("my test suite", (): void => {
|
|
9
|
-
* // put your tests here
|
|
10
|
-
* });
|
|
11
|
-
*/
|
|
12
|
-
declare function describe(description: string, callback: () => void): void;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* This function creates a test inside the given test group. It must be placed inside a describe
|
|
16
|
-
* block.
|
|
17
|
-
*
|
|
18
|
-
* @param {string} description - This is the name of the test, and should describe a behavior.
|
|
19
|
-
* @param {() => void} callback - A function that contains a set of expectations for this test.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* describe("the meaning of life", (): void => {
|
|
23
|
-
* it("should be 42", (): void => {
|
|
24
|
-
* // put your expectations here
|
|
25
|
-
* expect<i32>(29 + 13).toBe(42);
|
|
26
|
-
* });
|
|
27
|
-
* });
|
|
28
|
-
*/
|
|
29
|
-
declare function it(description: string, callback: () => void): void;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* A test that does not run, and is longhand equivalent to using todo function without a
|
|
33
|
-
* callback. This test does not get run and is reported like a todo.
|
|
34
|
-
*
|
|
35
|
-
* @param {string} description - This is the name of the test, and should describe a behavior.
|
|
36
|
-
* @param {() => void} callback - A function that contains a set of expectations for this test.
|
|
37
|
-
*/
|
|
38
|
-
declare function xit(description: string, callback: () => void): void;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* A test that does not run, and is longhand equivalent to using todo function without a
|
|
42
|
-
* callback. This test does not get run and is reported like a todo.
|
|
43
|
-
*
|
|
44
|
-
* @param {string} description - This is the name of the test, and should describe a behavior.
|
|
45
|
-
* @param {() => void} callback - A function that contains a set of expectations for this test.
|
|
46
|
-
*/
|
|
47
|
-
declare function xtest(description: string, callback: () => void): void;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* This function creates a test inside the given test group. It must be placed inside a describe
|
|
51
|
-
* block.
|
|
52
|
-
*
|
|
53
|
-
* @param {string} description - This is the name of the test, and should describe a behavior.
|
|
54
|
-
* @param {() => void} callback - A function that contains a set of expectations for this test.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* describe("the meaning of life", (): void => {
|
|
58
|
-
* test("the value should be 42", (): void => {
|
|
59
|
-
* // put your expectations here
|
|
60
|
-
* expect<i32>(29 + 13).toBe(42);
|
|
61
|
-
* });
|
|
62
|
-
* });
|
|
63
|
-
*/
|
|
64
|
-
declare function test(description: string, callback: () => void): void;
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* This function creates a test that is expected to fail. This is useful to verify if a given
|
|
68
|
-
* behavior is expected to throw.
|
|
69
|
-
*
|
|
70
|
-
* @param {string} description - This is the name of the test, and should describe a behavior.
|
|
71
|
-
* @param {() => void} callback - A function that contains a set of expectations for this test.
|
|
72
|
-
* @param {string?} message - A message that describes why the test should fail.
|
|
73
|
-
* @example
|
|
74
|
-
* describe("the meaning of life", (): void => {
|
|
75
|
-
* throws("the value should be 42", (): void => {
|
|
76
|
-
* // put your expectations here
|
|
77
|
-
* expect<i32>(29 + 13).toBe(42);
|
|
78
|
-
* });
|
|
79
|
-
* });
|
|
80
|
-
*/
|
|
81
|
-
declare function throws(
|
|
82
|
-
description: string,
|
|
83
|
-
callback: () => void,
|
|
84
|
-
message?: string,
|
|
85
|
-
): void;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* This function creates a test that is expected to fail. This is useful to verify if a given
|
|
89
|
-
* behavior is expected to throw.
|
|
90
|
-
*
|
|
91
|
-
* @param {string} description - This is the name of the test, and should describe a behavior.
|
|
92
|
-
* @param {() => void} callback - A function that contains a set of expectations for this test.
|
|
93
|
-
* @param {string?} message - A message that describes why the test should fail.
|
|
94
|
-
* @example
|
|
95
|
-
* describe("the meaning of life", (): void => {
|
|
96
|
-
* itThrows("when the value should be 42", (): void => {
|
|
97
|
-
* // put your expectations here
|
|
98
|
-
* expect<i32>(29 + 13).not.toBe(42);
|
|
99
|
-
* }, "The value is actually 42.");
|
|
100
|
-
* });
|
|
101
|
-
*/
|
|
102
|
-
declare function itThrows(
|
|
103
|
-
description: string,
|
|
104
|
-
callback: () => void,
|
|
105
|
-
message?: string,
|
|
106
|
-
): void;
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* This function creates a callback that is called before each individual test is run in this test
|
|
110
|
-
* group.
|
|
111
|
-
*
|
|
112
|
-
* @param {function} callback - The function to be run before each test in the current test group.
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* // create a global
|
|
116
|
-
* var cat: Cat = new Cat();
|
|
117
|
-
*
|
|
118
|
-
* describe("cats", (): void => {
|
|
119
|
-
* beforeEach((): void => {
|
|
120
|
-
* cat.meow(1); // meow once per test
|
|
121
|
-
* });
|
|
122
|
-
* });
|
|
123
|
-
*/
|
|
124
|
-
declare function beforeEach(callback: () => void): void;
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* This function creates a callback that is called before the whole test group is run, and only
|
|
128
|
-
* once.
|
|
129
|
-
*
|
|
130
|
-
* @param {function} callback - The function to be run before each test in the current test group.
|
|
131
|
-
*
|
|
132
|
-
* @example
|
|
133
|
-
* // create a global
|
|
134
|
-
* var dog: Dog = null;
|
|
135
|
-
* describe("dogs", (): void => {
|
|
136
|
-
* beforeAll((): void => {
|
|
137
|
-
* dog = new Dog(); // create a single dog once before the tests start
|
|
138
|
-
* });
|
|
139
|
-
* });
|
|
140
|
-
*/
|
|
141
|
-
declare function beforeAll(callback: () => void): void;
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* This function creates a callback that is called after each individual test is run in this test
|
|
145
|
-
* group.
|
|
146
|
-
*
|
|
147
|
-
* @param {function} callback - The function to be run after each test in the current test group.
|
|
148
|
-
*
|
|
149
|
-
* @example
|
|
150
|
-
* // create a global
|
|
151
|
-
* var cat: Cat = new Cat();
|
|
152
|
-
*
|
|
153
|
-
* describe("cats", (): void => {
|
|
154
|
-
* afterEach((): void => {
|
|
155
|
-
* cat.sleep(12); // cats sleep a lot
|
|
156
|
-
* });
|
|
157
|
-
* });
|
|
158
|
-
*/
|
|
159
|
-
declare function afterEach(callback: () => void): void;
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* This function creates a callback that is called after the whole test group is run, and only
|
|
163
|
-
* once.
|
|
164
|
-
*
|
|
165
|
-
* @param {function} callback - The function to be run after each test in the current test group.
|
|
166
|
-
*
|
|
167
|
-
* @example
|
|
168
|
-
* // create a global
|
|
169
|
-
* var dog: Dog = null;
|
|
170
|
-
* describe("dogs", (): void => {
|
|
171
|
-
* afterAll((): void => {
|
|
172
|
-
* memory.free(changetype<usize>(dog)); // free some memory
|
|
173
|
-
* });
|
|
174
|
-
* });
|
|
175
|
-
*/
|
|
176
|
-
declare function afterAll(callback: () => void): void;
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Describes a value and returns an expectation to test the value.
|
|
180
|
-
*
|
|
181
|
-
* @type {T} - The expectation's type.
|
|
182
|
-
* @param {T} actual - The value being tested.
|
|
183
|
-
*
|
|
184
|
-
* @example
|
|
185
|
-
* expect<i32>(42).not.toBe(-1, "42 should not be -1");
|
|
186
|
-
* expect<i32>(19 + 23).toBe(42, "19 + 23 should equal 42");
|
|
187
|
-
*/
|
|
188
|
-
declare function expect<T>(actual: T | null): Expectation<T>;
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* An expectation for a value.
|
|
192
|
-
*/
|
|
193
|
-
// @ts-ignore
|
|
194
|
-
declare class Expectation<T> {
|
|
195
|
-
/**
|
|
196
|
-
* This expectation performs a strict equality on value types and reference types.
|
|
197
|
-
*
|
|
198
|
-
* @param {T | null} expected - The value to be compared.
|
|
199
|
-
* @param {string} message - The optional message that describes the expectation.
|
|
200
|
-
*
|
|
201
|
-
* @example
|
|
202
|
-
* expect<i32>(42).not.toBe(-1, "42 should not be -1");
|
|
203
|
-
* expect<i32>(19 + 23).toBe(42, "19 + 23 should equal 42");
|
|
204
|
-
*/
|
|
205
|
-
toBe(expected: T | null, message?: string): void;
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* If the value is callable, it calls the function, and fails the expectation if it throws, or hits
|
|
209
|
-
* an unreachable().
|
|
210
|
-
*
|
|
211
|
-
* @param {string} message - The optional message that describes the expectation.
|
|
212
|
-
*
|
|
213
|
-
* @example
|
|
214
|
-
* expectFn((): void => unreachable()).toThrow("unreachable() should throw.");
|
|
215
|
-
* expectFn((): void => {
|
|
216
|
-
* cat.sleep(100); // cats can sleep quite a lot
|
|
217
|
-
* }).not.toThrow("cats should sleep, not throw");
|
|
218
|
-
*/
|
|
219
|
-
toThrow(message?: string): void;
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* This expecation asserts that the value is truthy, like in javascript. If the value is a string,
|
|
223
|
-
* then strings of length 0 are not truthy.
|
|
224
|
-
*
|
|
225
|
-
* @param {string} message - The optional message that describes the expectation.
|
|
226
|
-
*
|
|
227
|
-
* @example
|
|
228
|
-
* expect<bool>(true).toBeTruthy("true is truthy.");
|
|
229
|
-
* expect<i32>(1).toBeTruthy("numeric values that are not 0 are truthy.");
|
|
230
|
-
* expect<Vec3>(new Vec3(1, 2, 3)).toBeTruthy("reference types that aren't null are truthy.");
|
|
231
|
-
* expect<bool>(false).not.toBeTruthy("false is not truthy.");
|
|
232
|
-
* expect<i32>(0).not.toBeTruthy("0 is not truthy.");
|
|
233
|
-
* expect<Vec3>(null).not.toBeTruthy("null is not truthy.");
|
|
234
|
-
*/
|
|
235
|
-
toBeTruthy(message?: string): void;
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* This expectation tests the value to see if it is null. If the value is a value type, it is
|
|
239
|
-
* never null. If the value is a reference type, it performs a strict null comparison.
|
|
240
|
-
*
|
|
241
|
-
* @param {string} message - The optional message that describes the expectation.
|
|
242
|
-
*
|
|
243
|
-
* @example
|
|
244
|
-
* expect<i32>(0).not.toBeNull("numbers are never null");
|
|
245
|
-
* expect<Vec3>(null).toBeNull("null reference types are null.");
|
|
246
|
-
*/
|
|
247
|
-
toBeNull(message?: string): void;
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* This expecation assert that the value is falsy, like in javascript. If the value is a string,
|
|
251
|
-
* then strings of length 0 are falsy.
|
|
252
|
-
*
|
|
253
|
-
* @param {string} message - The optional message that describes the expectation.
|
|
254
|
-
*
|
|
255
|
-
* @example
|
|
256
|
-
* expect<bool>(false).toBeFalsy("false is falsy.");
|
|
257
|
-
* expect<i32>(0).toBeFalsy("0 is falsy.");
|
|
258
|
-
* expect<Vec3>(null).toBeFalsy("null is falsy.");
|
|
259
|
-
* expect<bool>(true).not.toBeFalsy("true is not falsy.");
|
|
260
|
-
* expect<i32>(1).not.toBeFalsy("numeric values that are not 0 are not falsy.");
|
|
261
|
-
* expect<Vec3>(new Vec3(1, 2, 3)).not.toBeFalsy("reference types that aren't null are not falsy.");
|
|
262
|
-
*/
|
|
263
|
-
toBeFalsy(message?: string): void;
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* This expectation asserts that the value is greater than the expected value. Since operators can
|
|
267
|
-
* be overloaded in assemblyscript, it's possible for this to work on reference types.
|
|
268
|
-
*
|
|
269
|
-
* @param {T | null} expected - The expected value that the actual value should be greater than.
|
|
270
|
-
* @param {string} message - The optional message that describes this expectation.
|
|
271
|
-
*
|
|
272
|
-
* @example
|
|
273
|
-
* expect<i32>(10).toBeGreaterThan(4);
|
|
274
|
-
* expect<i32>(12).not.toBeGreaterThan(42);
|
|
275
|
-
*/
|
|
276
|
-
toBeGreaterThan(expected: T | null, message?: string): void;
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* This expectation asserts that the value is less than the expected value. Since operators can
|
|
280
|
-
* be overloaded in assemblyscript, it's possible for this to work on reference types.
|
|
281
|
-
*
|
|
282
|
-
* @param {T | null} value - The expected value that the actual value should be less than.
|
|
283
|
-
* @param {string} message - The optional message that describes this expectation.
|
|
284
|
-
*
|
|
285
|
-
* @example
|
|
286
|
-
* expect<i32>(10).not.toBeLessThan(4);
|
|
287
|
-
* expect<i32>(12).toBeLessThan(42);
|
|
288
|
-
*/
|
|
289
|
-
toBeLessThan(expected: T | null, message?: string): void;
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* This expectation asserts that the value is greater than or equal to the expected value. Since
|
|
293
|
-
* operators can be overloaded in assemblyscript, it's possible for this to work on reference
|
|
294
|
-
* types.
|
|
295
|
-
*
|
|
296
|
-
* @param {T | null} value - The expected value that the actual value should be greater than or
|
|
297
|
-
* equal to.
|
|
298
|
-
* @param {string} message - The optional message that describes this expectation.
|
|
299
|
-
*
|
|
300
|
-
* @example
|
|
301
|
-
* expect<i32>(42).toBeGreaterThanOrEqual(42);
|
|
302
|
-
* expect<i32>(10).toBeGreaterThanOrEqual(4);
|
|
303
|
-
* expect<i32>(12).not.toBeGreaterThanOrEqual(42);
|
|
304
|
-
*/
|
|
305
|
-
toBeGreaterThanOrEqual(expected: T | null, message?: string): void;
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* This expectation asserts that the value is less than or equal to the expected value. Since
|
|
309
|
-
* operators can be overloaded in assemblyscript, it's possible for this to work on reference
|
|
310
|
-
* types.
|
|
311
|
-
*
|
|
312
|
-
* @param {T | null} value - The expected value that the actual value should be less than or equal
|
|
313
|
-
* to.
|
|
314
|
-
* @param {string} message - The optional message that describes this expectation.
|
|
315
|
-
*
|
|
316
|
-
* @example
|
|
317
|
-
* expect<i32>(42).toBeLessThanOrEqual(42);
|
|
318
|
-
* expect<i32>(10).not.toBeLessThanOrEqual(4);
|
|
319
|
-
* expect<i32>(12).toBeLessThanOrEqual(42);
|
|
320
|
-
*/
|
|
321
|
-
toBeLessThanOrEqual(expected: T | null, message?: string): void;
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* This expectation asserts that the value is close to another value. Both numbers must be finite,
|
|
325
|
-
* and T must extend f64 or f32.
|
|
326
|
-
*
|
|
327
|
-
* @param {T extends f64 | f32} value - The expected value to be close to.
|
|
328
|
-
* @param {i32} decimalPlaces - The number of decimal places used to calculate epsilon. Default is
|
|
329
|
-
* 2.
|
|
330
|
-
* @param {string} message - The optional message that describes this expectation.
|
|
331
|
-
*/
|
|
332
|
-
toBeCloseTo(expected: T, decimalPlaces?: number, message?: string): void;
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* This function asserts the float type value is NaN.
|
|
336
|
-
*
|
|
337
|
-
* @param {string} message - The optional message the describes this expectation.
|
|
338
|
-
* @example
|
|
339
|
-
* expect<f64>(NaN).toBeNaN();
|
|
340
|
-
* expect<f32>(42).not.toBeNaN();
|
|
341
|
-
*/
|
|
342
|
-
toBeNaN(message?: string): void;
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* This function asserts a float is finite.
|
|
346
|
-
*
|
|
347
|
-
* @param {string} message - The optional message the describes this expectation.
|
|
348
|
-
* @example
|
|
349
|
-
* expect<f32>(42).toBeFinite();
|
|
350
|
-
* expect<f64>(Infinity).not.toBeFinite();
|
|
351
|
-
*/
|
|
352
|
-
toBeFinite(message?: string): void;
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* This method asserts the item has the expected length.
|
|
356
|
-
*
|
|
357
|
-
* @param {i32} expected - The expected length.
|
|
358
|
-
* @param {string} message - The optional message the describes this expectation.
|
|
359
|
-
*/
|
|
360
|
-
toHaveLength(expected: i32, message?: string): void;
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* This method asserts that a given T that extends Array<U> has a value/reference included.
|
|
364
|
-
*
|
|
365
|
-
* @param {i32} expected - The expected item to be included in the Array.
|
|
366
|
-
* @param {string} message - The optional message the describes this expectation.
|
|
367
|
-
*/
|
|
368
|
-
// @ts-ignore: expected value should be known at compile time
|
|
369
|
-
toContain(expected: valueof<T>, message?: string): void;
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* This method asserts that a given T that extends Array<U> has a value/reference included and
|
|
373
|
-
* compared via memory.compare().
|
|
374
|
-
*
|
|
375
|
-
* @param {i32} expected - The expected item to be included in the Array.
|
|
376
|
-
* @param {string} message - The optional message the describes this expectation.
|
|
377
|
-
*/
|
|
378
|
-
// @ts-ignore: expected value should be known at compile time
|
|
379
|
-
toContainEqual(expected: valueof<T>, message?: string): void;
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* This computed property is chainable, and negates the existing expectation. It returns itself.
|
|
383
|
-
*
|
|
384
|
-
* @param {U} expected - The expected item.
|
|
385
|
-
* @param {string} message - The optional message the describes this expectation.
|
|
386
|
-
* @type {Expectation<T>}
|
|
387
|
-
*/
|
|
388
|
-
not: Expectation<T>;
|
|
389
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* This function creates a test group in the test loader.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} description - This is the name of the test group.
|
|
5
|
+
* @param {() => void} callback - A function that contains all of the closures for this test group.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* describe("my test suite", (): void => {
|
|
9
|
+
* // put your tests here
|
|
10
|
+
* });
|
|
11
|
+
*/
|
|
12
|
+
declare function describe(description: string, callback: () => void): void;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This function creates a test inside the given test group. It must be placed inside a describe
|
|
16
|
+
* block.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} description - This is the name of the test, and should describe a behavior.
|
|
19
|
+
* @param {() => void} callback - A function that contains a set of expectations for this test.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* describe("the meaning of life", (): void => {
|
|
23
|
+
* it("should be 42", (): void => {
|
|
24
|
+
* // put your expectations here
|
|
25
|
+
* expect<i32>(29 + 13).toBe(42);
|
|
26
|
+
* });
|
|
27
|
+
* });
|
|
28
|
+
*/
|
|
29
|
+
declare function it(description: string, callback: () => void): void;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A test that does not run, and is longhand equivalent to using todo function without a
|
|
33
|
+
* callback. This test does not get run and is reported like a todo.
|
|
34
|
+
*
|
|
35
|
+
* @param {string} description - This is the name of the test, and should describe a behavior.
|
|
36
|
+
* @param {() => void} callback - A function that contains a set of expectations for this test.
|
|
37
|
+
*/
|
|
38
|
+
declare function xit(description: string, callback: () => void): void;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A test that does not run, and is longhand equivalent to using todo function without a
|
|
42
|
+
* callback. This test does not get run and is reported like a todo.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} description - This is the name of the test, and should describe a behavior.
|
|
45
|
+
* @param {() => void} callback - A function that contains a set of expectations for this test.
|
|
46
|
+
*/
|
|
47
|
+
declare function xtest(description: string, callback: () => void): void;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* This function creates a test inside the given test group. It must be placed inside a describe
|
|
51
|
+
* block.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} description - This is the name of the test, and should describe a behavior.
|
|
54
|
+
* @param {() => void} callback - A function that contains a set of expectations for this test.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* describe("the meaning of life", (): void => {
|
|
58
|
+
* test("the value should be 42", (): void => {
|
|
59
|
+
* // put your expectations here
|
|
60
|
+
* expect<i32>(29 + 13).toBe(42);
|
|
61
|
+
* });
|
|
62
|
+
* });
|
|
63
|
+
*/
|
|
64
|
+
declare function test(description: string, callback: () => void): void;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* This function creates a test that is expected to fail. This is useful to verify if a given
|
|
68
|
+
* behavior is expected to throw.
|
|
69
|
+
*
|
|
70
|
+
* @param {string} description - This is the name of the test, and should describe a behavior.
|
|
71
|
+
* @param {() => void} callback - A function that contains a set of expectations for this test.
|
|
72
|
+
* @param {string?} message - A message that describes why the test should fail.
|
|
73
|
+
* @example
|
|
74
|
+
* describe("the meaning of life", (): void => {
|
|
75
|
+
* throws("the value should be 42", (): void => {
|
|
76
|
+
* // put your expectations here
|
|
77
|
+
* expect<i32>(29 + 13).toBe(42);
|
|
78
|
+
* });
|
|
79
|
+
* });
|
|
80
|
+
*/
|
|
81
|
+
declare function throws(
|
|
82
|
+
description: string,
|
|
83
|
+
callback: () => void,
|
|
84
|
+
message?: string,
|
|
85
|
+
): void;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* This function creates a test that is expected to fail. This is useful to verify if a given
|
|
89
|
+
* behavior is expected to throw.
|
|
90
|
+
*
|
|
91
|
+
* @param {string} description - This is the name of the test, and should describe a behavior.
|
|
92
|
+
* @param {() => void} callback - A function that contains a set of expectations for this test.
|
|
93
|
+
* @param {string?} message - A message that describes why the test should fail.
|
|
94
|
+
* @example
|
|
95
|
+
* describe("the meaning of life", (): void => {
|
|
96
|
+
* itThrows("when the value should be 42", (): void => {
|
|
97
|
+
* // put your expectations here
|
|
98
|
+
* expect<i32>(29 + 13).not.toBe(42);
|
|
99
|
+
* }, "The value is actually 42.");
|
|
100
|
+
* });
|
|
101
|
+
*/
|
|
102
|
+
declare function itThrows(
|
|
103
|
+
description: string,
|
|
104
|
+
callback: () => void,
|
|
105
|
+
message?: string,
|
|
106
|
+
): void;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* This function creates a callback that is called before each individual test is run in this test
|
|
110
|
+
* group.
|
|
111
|
+
*
|
|
112
|
+
* @param {function} callback - The function to be run before each test in the current test group.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* // create a global
|
|
116
|
+
* var cat: Cat = new Cat();
|
|
117
|
+
*
|
|
118
|
+
* describe("cats", (): void => {
|
|
119
|
+
* beforeEach((): void => {
|
|
120
|
+
* cat.meow(1); // meow once per test
|
|
121
|
+
* });
|
|
122
|
+
* });
|
|
123
|
+
*/
|
|
124
|
+
declare function beforeEach(callback: () => void): void;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* This function creates a callback that is called before the whole test group is run, and only
|
|
128
|
+
* once.
|
|
129
|
+
*
|
|
130
|
+
* @param {function} callback - The function to be run before each test in the current test group.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* // create a global
|
|
134
|
+
* var dog: Dog = null;
|
|
135
|
+
* describe("dogs", (): void => {
|
|
136
|
+
* beforeAll((): void => {
|
|
137
|
+
* dog = new Dog(); // create a single dog once before the tests start
|
|
138
|
+
* });
|
|
139
|
+
* });
|
|
140
|
+
*/
|
|
141
|
+
declare function beforeAll(callback: () => void): void;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* This function creates a callback that is called after each individual test is run in this test
|
|
145
|
+
* group.
|
|
146
|
+
*
|
|
147
|
+
* @param {function} callback - The function to be run after each test in the current test group.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* // create a global
|
|
151
|
+
* var cat: Cat = new Cat();
|
|
152
|
+
*
|
|
153
|
+
* describe("cats", (): void => {
|
|
154
|
+
* afterEach((): void => {
|
|
155
|
+
* cat.sleep(12); // cats sleep a lot
|
|
156
|
+
* });
|
|
157
|
+
* });
|
|
158
|
+
*/
|
|
159
|
+
declare function afterEach(callback: () => void): void;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* This function creates a callback that is called after the whole test group is run, and only
|
|
163
|
+
* once.
|
|
164
|
+
*
|
|
165
|
+
* @param {function} callback - The function to be run after each test in the current test group.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* // create a global
|
|
169
|
+
* var dog: Dog = null;
|
|
170
|
+
* describe("dogs", (): void => {
|
|
171
|
+
* afterAll((): void => {
|
|
172
|
+
* memory.free(changetype<usize>(dog)); // free some memory
|
|
173
|
+
* });
|
|
174
|
+
* });
|
|
175
|
+
*/
|
|
176
|
+
declare function afterAll(callback: () => void): void;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Describes a value and returns an expectation to test the value.
|
|
180
|
+
*
|
|
181
|
+
* @type {T} - The expectation's type.
|
|
182
|
+
* @param {T} actual - The value being tested.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* expect<i32>(42).not.toBe(-1, "42 should not be -1");
|
|
186
|
+
* expect<i32>(19 + 23).toBe(42, "19 + 23 should equal 42");
|
|
187
|
+
*/
|
|
188
|
+
declare function expect<T>(actual: T | null): Expectation<T>;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* An expectation for a value.
|
|
192
|
+
*/
|
|
193
|
+
// @ts-ignore
|
|
194
|
+
declare class Expectation<T> {
|
|
195
|
+
/**
|
|
196
|
+
* This expectation performs a strict equality on value types and reference types.
|
|
197
|
+
*
|
|
198
|
+
* @param {T | null} expected - The value to be compared.
|
|
199
|
+
* @param {string} message - The optional message that describes the expectation.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* expect<i32>(42).not.toBe(-1, "42 should not be -1");
|
|
203
|
+
* expect<i32>(19 + 23).toBe(42, "19 + 23 should equal 42");
|
|
204
|
+
*/
|
|
205
|
+
toBe(expected: T | null, message?: string): void;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* If the value is callable, it calls the function, and fails the expectation if it throws, or hits
|
|
209
|
+
* an unreachable().
|
|
210
|
+
*
|
|
211
|
+
* @param {string} message - The optional message that describes the expectation.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* expectFn((): void => unreachable()).toThrow("unreachable() should throw.");
|
|
215
|
+
* expectFn((): void => {
|
|
216
|
+
* cat.sleep(100); // cats can sleep quite a lot
|
|
217
|
+
* }).not.toThrow("cats should sleep, not throw");
|
|
218
|
+
*/
|
|
219
|
+
toThrow(message?: string): void;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* This expecation asserts that the value is truthy, like in javascript. If the value is a string,
|
|
223
|
+
* then strings of length 0 are not truthy.
|
|
224
|
+
*
|
|
225
|
+
* @param {string} message - The optional message that describes the expectation.
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* expect<bool>(true).toBeTruthy("true is truthy.");
|
|
229
|
+
* expect<i32>(1).toBeTruthy("numeric values that are not 0 are truthy.");
|
|
230
|
+
* expect<Vec3>(new Vec3(1, 2, 3)).toBeTruthy("reference types that aren't null are truthy.");
|
|
231
|
+
* expect<bool>(false).not.toBeTruthy("false is not truthy.");
|
|
232
|
+
* expect<i32>(0).not.toBeTruthy("0 is not truthy.");
|
|
233
|
+
* expect<Vec3>(null).not.toBeTruthy("null is not truthy.");
|
|
234
|
+
*/
|
|
235
|
+
toBeTruthy(message?: string): void;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* This expectation tests the value to see if it is null. If the value is a value type, it is
|
|
239
|
+
* never null. If the value is a reference type, it performs a strict null comparison.
|
|
240
|
+
*
|
|
241
|
+
* @param {string} message - The optional message that describes the expectation.
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* expect<i32>(0).not.toBeNull("numbers are never null");
|
|
245
|
+
* expect<Vec3>(null).toBeNull("null reference types are null.");
|
|
246
|
+
*/
|
|
247
|
+
toBeNull(message?: string): void;
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* This expecation assert that the value is falsy, like in javascript. If the value is a string,
|
|
251
|
+
* then strings of length 0 are falsy.
|
|
252
|
+
*
|
|
253
|
+
* @param {string} message - The optional message that describes the expectation.
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* expect<bool>(false).toBeFalsy("false is falsy.");
|
|
257
|
+
* expect<i32>(0).toBeFalsy("0 is falsy.");
|
|
258
|
+
* expect<Vec3>(null).toBeFalsy("null is falsy.");
|
|
259
|
+
* expect<bool>(true).not.toBeFalsy("true is not falsy.");
|
|
260
|
+
* expect<i32>(1).not.toBeFalsy("numeric values that are not 0 are not falsy.");
|
|
261
|
+
* expect<Vec3>(new Vec3(1, 2, 3)).not.toBeFalsy("reference types that aren't null are not falsy.");
|
|
262
|
+
*/
|
|
263
|
+
toBeFalsy(message?: string): void;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* This expectation asserts that the value is greater than the expected value. Since operators can
|
|
267
|
+
* be overloaded in assemblyscript, it's possible for this to work on reference types.
|
|
268
|
+
*
|
|
269
|
+
* @param {T | null} expected - The expected value that the actual value should be greater than.
|
|
270
|
+
* @param {string} message - The optional message that describes this expectation.
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* expect<i32>(10).toBeGreaterThan(4);
|
|
274
|
+
* expect<i32>(12).not.toBeGreaterThan(42);
|
|
275
|
+
*/
|
|
276
|
+
toBeGreaterThan(expected: T | null, message?: string): void;
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* This expectation asserts that the value is less than the expected value. Since operators can
|
|
280
|
+
* be overloaded in assemblyscript, it's possible for this to work on reference types.
|
|
281
|
+
*
|
|
282
|
+
* @param {T | null} value - The expected value that the actual value should be less than.
|
|
283
|
+
* @param {string} message - The optional message that describes this expectation.
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* expect<i32>(10).not.toBeLessThan(4);
|
|
287
|
+
* expect<i32>(12).toBeLessThan(42);
|
|
288
|
+
*/
|
|
289
|
+
toBeLessThan(expected: T | null, message?: string): void;
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* This expectation asserts that the value is greater than or equal to the expected value. Since
|
|
293
|
+
* operators can be overloaded in assemblyscript, it's possible for this to work on reference
|
|
294
|
+
* types.
|
|
295
|
+
*
|
|
296
|
+
* @param {T | null} value - The expected value that the actual value should be greater than or
|
|
297
|
+
* equal to.
|
|
298
|
+
* @param {string} message - The optional message that describes this expectation.
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* expect<i32>(42).toBeGreaterThanOrEqual(42);
|
|
302
|
+
* expect<i32>(10).toBeGreaterThanOrEqual(4);
|
|
303
|
+
* expect<i32>(12).not.toBeGreaterThanOrEqual(42);
|
|
304
|
+
*/
|
|
305
|
+
toBeGreaterThanOrEqual(expected: T | null, message?: string): void;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* This expectation asserts that the value is less than or equal to the expected value. Since
|
|
309
|
+
* operators can be overloaded in assemblyscript, it's possible for this to work on reference
|
|
310
|
+
* types.
|
|
311
|
+
*
|
|
312
|
+
* @param {T | null} value - The expected value that the actual value should be less than or equal
|
|
313
|
+
* to.
|
|
314
|
+
* @param {string} message - The optional message that describes this expectation.
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* expect<i32>(42).toBeLessThanOrEqual(42);
|
|
318
|
+
* expect<i32>(10).not.toBeLessThanOrEqual(4);
|
|
319
|
+
* expect<i32>(12).toBeLessThanOrEqual(42);
|
|
320
|
+
*/
|
|
321
|
+
toBeLessThanOrEqual(expected: T | null, message?: string): void;
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* This expectation asserts that the value is close to another value. Both numbers must be finite,
|
|
325
|
+
* and T must extend f64 or f32.
|
|
326
|
+
*
|
|
327
|
+
* @param {T extends f64 | f32} value - The expected value to be close to.
|
|
328
|
+
* @param {i32} decimalPlaces - The number of decimal places used to calculate epsilon. Default is
|
|
329
|
+
* 2.
|
|
330
|
+
* @param {string} message - The optional message that describes this expectation.
|
|
331
|
+
*/
|
|
332
|
+
toBeCloseTo(expected: T, decimalPlaces?: number, message?: string): void;
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* This function asserts the float type value is NaN.
|
|
336
|
+
*
|
|
337
|
+
* @param {string} message - The optional message the describes this expectation.
|
|
338
|
+
* @example
|
|
339
|
+
* expect<f64>(NaN).toBeNaN();
|
|
340
|
+
* expect<f32>(42).not.toBeNaN();
|
|
341
|
+
*/
|
|
342
|
+
toBeNaN(message?: string): void;
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* This function asserts a float is finite.
|
|
346
|
+
*
|
|
347
|
+
* @param {string} message - The optional message the describes this expectation.
|
|
348
|
+
* @example
|
|
349
|
+
* expect<f32>(42).toBeFinite();
|
|
350
|
+
* expect<f64>(Infinity).not.toBeFinite();
|
|
351
|
+
*/
|
|
352
|
+
toBeFinite(message?: string): void;
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* This method asserts the item has the expected length.
|
|
356
|
+
*
|
|
357
|
+
* @param {i32} expected - The expected length.
|
|
358
|
+
* @param {string} message - The optional message the describes this expectation.
|
|
359
|
+
*/
|
|
360
|
+
toHaveLength(expected: i32, message?: string): void;
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* This method asserts that a given T that extends Array<U> has a value/reference included.
|
|
364
|
+
*
|
|
365
|
+
* @param {i32} expected - The expected item to be included in the Array.
|
|
366
|
+
* @param {string} message - The optional message the describes this expectation.
|
|
367
|
+
*/
|
|
368
|
+
// @ts-ignore: expected value should be known at compile time
|
|
369
|
+
toContain(expected: valueof<T>, message?: string): void;
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* This method asserts that a given T that extends Array<U> has a value/reference included and
|
|
373
|
+
* compared via memory.compare().
|
|
374
|
+
*
|
|
375
|
+
* @param {i32} expected - The expected item to be included in the Array.
|
|
376
|
+
* @param {string} message - The optional message the describes this expectation.
|
|
377
|
+
*/
|
|
378
|
+
// @ts-ignore: expected value should be known at compile time
|
|
379
|
+
toContainEqual(expected: valueof<T>, message?: string): void;
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* This computed property is chainable, and negates the existing expectation. It returns itself.
|
|
383
|
+
*
|
|
384
|
+
* @param {U} expected - The expected item.
|
|
385
|
+
* @param {string} message - The optional message the describes this expectation.
|
|
386
|
+
* @type {Expectation<T>}
|
|
387
|
+
*/
|
|
388
|
+
not: Expectation<T>;
|
|
389
|
+
}
|