@react-native-harness/runtime 1.0.0-alpha.1 → 1.0.0-alpha.11

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.
Files changed (105) hide show
  1. package/dist/bundler/bundle.d.ts.map +1 -1
  2. package/dist/bundler/bundle.js +7 -1
  3. package/dist/bundler/errors.d.ts +5 -0
  4. package/dist/bundler/errors.d.ts.map +1 -1
  5. package/dist/bundler/errors.js +10 -0
  6. package/dist/bundler/factory.d.ts +3 -0
  7. package/dist/bundler/factory.d.ts.map +1 -0
  8. package/dist/bundler/factory.js +36 -0
  9. package/dist/bundler/index.d.ts +2 -1
  10. package/dist/bundler/index.d.ts.map +1 -1
  11. package/dist/bundler/index.js +1 -1
  12. package/dist/bundler/types.d.ts +7 -0
  13. package/dist/bundler/types.d.ts.map +1 -0
  14. package/dist/bundler/types.js +1 -0
  15. package/dist/client/factory.d.ts.map +1 -1
  16. package/dist/client/factory.js +13 -4
  17. package/dist/initialize.js +8 -6
  18. package/dist/mocker/registry.d.ts +2 -2
  19. package/dist/mocker/registry.d.ts.map +1 -1
  20. package/dist/runner/errors.d.ts +4 -2
  21. package/dist/runner/errors.d.ts.map +1 -1
  22. package/dist/runner/errors.js +21 -3
  23. package/dist/runner/runSuite.d.ts.map +1 -1
  24. package/dist/runner/runSuite.js +22 -7
  25. package/dist/symbolicate.d.ts +3 -0
  26. package/dist/symbolicate.d.ts.map +1 -0
  27. package/dist/symbolicate.js +18 -0
  28. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  29. package/dist/utils/progressLogger.d.ts +8 -0
  30. package/dist/utils/progressLogger.d.ts.map +1 -0
  31. package/dist/utils/progressLogger.js +79 -0
  32. package/package.json +7 -5
  33. package/src/bundler/bundle.ts +9 -1
  34. package/src/bundler/errors.ts +10 -0
  35. package/src/bundler/factory.ts +43 -0
  36. package/src/bundler/index.ts +2 -1
  37. package/src/bundler/types.ts +7 -0
  38. package/src/client/factory.ts +21 -6
  39. package/src/initialize.ts +11 -8
  40. package/src/mocker/registry.ts +3 -3
  41. package/src/react-native.d.ts +37 -0
  42. package/src/runner/errors.ts +35 -5
  43. package/src/runner/runSuite.ts +27 -9
  44. package/src/symbolicate.ts +22 -0
  45. package/src/utils/progressLogger.ts +98 -0
  46. package/dist/bundler/dev-server.d.ts +0 -2
  47. package/dist/bundler/dev-server.d.ts.map +0 -1
  48. package/dist/bundler/dev-server.js +0 -5
  49. package/dist/exports.d.ts +0 -7
  50. package/dist/exports.d.ts.map +0 -1
  51. package/dist/exports.js +0 -6
  52. package/dist/getEntryComponent.d.ts +0 -6
  53. package/dist/getEntryComponent.d.ts.map +0 -1
  54. package/dist/getEntryComponent.js +0 -6
  55. package/dist/logger.d.ts +0 -6
  56. package/dist/logger.d.ts.map +0 -1
  57. package/dist/logger.js +0 -14
  58. package/dist/mock.d.ts +0 -15
  59. package/dist/mock.d.ts.map +0 -1
  60. package/dist/mock.js +0 -37
  61. package/dist/module.d.ts +0 -3
  62. package/dist/module.d.ts.map +0 -1
  63. package/dist/module.js +0 -19
  64. package/dist/module.web.d.ts +0 -2
  65. package/dist/module.web.d.ts.map +0 -1
  66. package/dist/module.web.js +0 -12
  67. package/dist/rntl/client.d.ts +0 -3
  68. package/dist/rntl/client.d.ts.map +0 -1
  69. package/dist/rntl/client.js +0 -8
  70. package/dist/rntl/describe.d.ts +0 -2
  71. package/dist/rntl/describe.d.ts.map +0 -1
  72. package/dist/rntl/describe.js +0 -1
  73. package/dist/rntl/expect.d.ts +0 -128
  74. package/dist/rntl/expect.d.ts.map +0 -1
  75. package/dist/rntl/expect.js +0 -670
  76. package/dist/rntl/fn.d.ts +0 -2
  77. package/dist/rntl/fn.d.ts.map +0 -1
  78. package/dist/rntl/fn.js +0 -1
  79. package/dist/rntl/mock.d.ts +0 -2
  80. package/dist/rntl/mock.d.ts.map +0 -1
  81. package/dist/rntl/mock.js +0 -1
  82. package/dist/rntl/render.d.ts +0 -4
  83. package/dist/rntl/render.d.ts.map +0 -1
  84. package/dist/rntl/render.js +0 -11
  85. package/dist/rntl/screen.d.ts +0 -45
  86. package/dist/rntl/screen.d.ts.map +0 -1
  87. package/dist/rntl/screen.js +0 -31
  88. package/dist/rntl/spies.d.ts +0 -45
  89. package/dist/rntl/spies.d.ts.map +0 -1
  90. package/dist/rntl/spies.js +0 -553
  91. package/dist/rntl/userEvent.d.ts +0 -22
  92. package/dist/rntl/userEvent.d.ts.map +0 -1
  93. package/dist/rntl/userEvent.js +0 -19
  94. package/dist/runner.d.ts +0 -7
  95. package/dist/runner.d.ts.map +0 -1
  96. package/dist/runner.js +0 -201
  97. package/dist/runtime.d.ts +0 -2
  98. package/dist/runtime.d.ts.map +0 -1
  99. package/dist/runtime.js +0 -44
  100. package/dist/state.d.ts +0 -25
  101. package/dist/state.d.ts.map +0 -1
  102. package/dist/state.js +0 -37
  103. package/dist/ui/UI.d.ts +0 -13
  104. package/dist/ui/UI.d.ts.map +0 -1
  105. package/dist/ui/UI.js +0 -121
@@ -1,670 +0,0 @@
1
- // Symbol to identify asymmetric matchers
2
- const ASYMMETRIC_MATCHER = Symbol('asymmetric-matcher');
3
- // Asymmetric matcher implementations
4
- class AnythingMatcher {
5
- [ASYMMETRIC_MATCHER] = true;
6
- asymmetricMatch(other) {
7
- return other !== null && other !== undefined;
8
- }
9
- toString() {
10
- return 'Anything';
11
- }
12
- }
13
- class AnyMatcher {
14
- expectedType;
15
- [ASYMMETRIC_MATCHER] = true;
16
- constructor(expectedType) {
17
- this.expectedType = expectedType;
18
- }
19
- asymmetricMatch(other) {
20
- if (this.expectedType === String) {
21
- return typeof other === 'string';
22
- }
23
- if (this.expectedType === Number) {
24
- return typeof other === 'number';
25
- }
26
- if (this.expectedType === Boolean) {
27
- return typeof other === 'boolean';
28
- }
29
- if (this.expectedType === Array) {
30
- return Array.isArray(other);
31
- }
32
- if (this.expectedType === Object) {
33
- return (typeof other === 'object' && other !== null && !Array.isArray(other));
34
- }
35
- return other instanceof this.expectedType;
36
- }
37
- toString() {
38
- return `Any<${this.expectedType.name}>`;
39
- }
40
- }
41
- class ArrayContainingMatcher {
42
- expectedArray;
43
- [ASYMMETRIC_MATCHER] = true;
44
- constructor(expectedArray) {
45
- this.expectedArray = expectedArray;
46
- }
47
- asymmetricMatch(other) {
48
- if (!Array.isArray(other)) {
49
- return false;
50
- }
51
- return this.expectedArray.every((expectedItem) => other.some((otherItem) => deepEqualWithAsymmetric(otherItem, expectedItem)));
52
- }
53
- toString() {
54
- return `ArrayContaining [${this.expectedArray
55
- .map((item) => JSON.stringify(item))
56
- .join(', ')}]`;
57
- }
58
- }
59
- class ObjectContainingMatcher {
60
- expectedObject;
61
- [ASYMMETRIC_MATCHER] = true;
62
- constructor(expectedObject) {
63
- this.expectedObject = expectedObject;
64
- }
65
- asymmetricMatch(other) {
66
- if (other == null || typeof other !== 'object' || Array.isArray(other)) {
67
- return false;
68
- }
69
- const otherObj = other;
70
- return Object.entries(this.expectedObject).every(([key, expectedValue]) => key in otherObj && deepEqualWithAsymmetric(otherObj[key], expectedValue));
71
- }
72
- toString() {
73
- return `ObjectContaining ${JSON.stringify(this.expectedObject)}`;
74
- }
75
- }
76
- class StringContainingMatcher {
77
- expectedString;
78
- [ASYMMETRIC_MATCHER] = true;
79
- constructor(expectedString) {
80
- this.expectedString = expectedString;
81
- }
82
- asymmetricMatch(other) {
83
- return typeof other === 'string' && other.includes(this.expectedString);
84
- }
85
- toString() {
86
- return `StringContaining "${this.expectedString}"`;
87
- }
88
- }
89
- class StringMatchingMatcher {
90
- expectedPattern;
91
- [ASYMMETRIC_MATCHER] = true;
92
- constructor(expectedPattern) {
93
- this.expectedPattern = expectedPattern;
94
- }
95
- asymmetricMatch(other) {
96
- if (typeof other !== 'string') {
97
- return false;
98
- }
99
- if (this.expectedPattern instanceof RegExp) {
100
- return this.expectedPattern.test(other);
101
- }
102
- return other.includes(this.expectedPattern);
103
- }
104
- toString() {
105
- return `StringMatching ${this.expectedPattern}`;
106
- }
107
- }
108
- class ArrayOfMatcher {
109
- expectedValue;
110
- [ASYMMETRIC_MATCHER] = true;
111
- constructor(expectedValue) {
112
- this.expectedValue = expectedValue;
113
- }
114
- asymmetricMatch(other) {
115
- if (!Array.isArray(other)) {
116
- return false;
117
- }
118
- return other.every((item) => deepEqualWithAsymmetric(item, this.expectedValue));
119
- }
120
- toString() {
121
- return `ArrayOf ${JSON.stringify(this.expectedValue)}`;
122
- }
123
- }
124
- class CloseToMatcher {
125
- expectedNumber;
126
- numDigits;
127
- [ASYMMETRIC_MATCHER] = true;
128
- constructor(expectedNumber, numDigits = 2) {
129
- this.expectedNumber = expectedNumber;
130
- this.numDigits = numDigits;
131
- }
132
- asymmetricMatch(other) {
133
- const otherNum = Number(other);
134
- if (Number.isNaN(otherNum)) {
135
- return false;
136
- }
137
- const diff = Math.abs(otherNum - this.expectedNumber);
138
- const precision = Math.pow(10, -this.numDigits) / 2;
139
- return diff < precision;
140
- }
141
- toString() {
142
- return `CloseTo ${this.expectedNumber} (precision: ${this.numDigits} digits)`;
143
- }
144
- }
145
- class NotMatcher {
146
- innerMatcher;
147
- [ASYMMETRIC_MATCHER] = true;
148
- constructor(innerMatcher) {
149
- this.innerMatcher = innerMatcher;
150
- }
151
- asymmetricMatch(other) {
152
- return !this.innerMatcher.asymmetricMatch(other);
153
- }
154
- toString() {
155
- return `Not ${this.innerMatcher.toString()}`;
156
- }
157
- }
158
- const isAsymmetricMatcher = (obj) => {
159
- return obj != null && typeof obj === 'object' && ASYMMETRIC_MATCHER in obj;
160
- };
161
- const deepEqualWithAsymmetric = (a, b) => {
162
- // Handle asymmetric matchers
163
- if (isAsymmetricMatcher(b)) {
164
- return b.asymmetricMatch(a);
165
- }
166
- if (isAsymmetricMatcher(a)) {
167
- return a.asymmetricMatch(b);
168
- }
169
- // Fall back to regular deep equal
170
- return deepEqual(a, b);
171
- };
172
- class ExpectError extends Error {
173
- constructor(message) {
174
- super(message);
175
- this.name = 'ExpectError';
176
- }
177
- }
178
- const deepEqual = (a, b) => {
179
- if (a === b)
180
- return true;
181
- if (a == null || b == null)
182
- return a === b;
183
- if (typeof a !== typeof b)
184
- return false;
185
- if (typeof a === 'object') {
186
- const aArray = Array.isArray(a);
187
- const bArray = Array.isArray(b);
188
- if (aArray !== bArray)
189
- return false;
190
- if (aArray) {
191
- const aArr = a;
192
- const bArr = b;
193
- if (aArr.length !== bArr.length)
194
- return false;
195
- return aArr.every((item, index) => deepEqualWithAsymmetric(item, bArr[index]));
196
- }
197
- const aObj = a;
198
- const bObj = b;
199
- const aKeys = Object.keys(aObj);
200
- const bKeys = Object.keys(bObj);
201
- if (aKeys.length !== bKeys.length)
202
- return false;
203
- return aKeys.every((key) => bKeys.includes(key) && deepEqualWithAsymmetric(aObj[key], bObj[key]));
204
- }
205
- return false;
206
- };
207
- const createMatchers = (actual, isNot = false) => {
208
- const assertResult = (result) => {
209
- const shouldPass = isNot ? !result.pass : result.pass;
210
- if (!shouldPass) {
211
- throw new ExpectError(result.message);
212
- }
213
- };
214
- return {
215
- toBe(expected) {
216
- const pass = Object.is(actual, expected);
217
- assertResult({
218
- pass,
219
- message: isNot
220
- ? `Expected ${actual} not to be ${expected}`
221
- : `Expected ${actual} to be ${expected}`,
222
- });
223
- },
224
- toEqual(expected) {
225
- const pass = deepEqual(actual, expected);
226
- assertResult({
227
- pass,
228
- message: isNot
229
- ? `Expected ${JSON.stringify(actual)} not to equal ${JSON.stringify(expected)}`
230
- : `Expected ${JSON.stringify(actual)} to equal ${JSON.stringify(expected)}`,
231
- });
232
- },
233
- toStrictEqual(expected) {
234
- // For now, same as toEqual - can be enhanced later for strict checking
235
- const pass = deepEqual(actual, expected);
236
- assertResult({
237
- pass,
238
- message: isNot
239
- ? `Expected ${JSON.stringify(actual)} not to strictly equal ${JSON.stringify(expected)}`
240
- : `Expected ${JSON.stringify(actual)} to strictly equal ${JSON.stringify(expected)}`,
241
- });
242
- },
243
- toBeTruthy() {
244
- const pass = Boolean(actual);
245
- assertResult({
246
- pass,
247
- message: isNot
248
- ? `Expected ${actual} not to be truthy`
249
- : `Expected ${actual} to be truthy`,
250
- });
251
- },
252
- toBeFalsy() {
253
- const pass = !actual;
254
- assertResult({
255
- pass,
256
- message: isNot
257
- ? `Expected ${actual} not to be falsy`
258
- : `Expected ${actual} to be falsy`,
259
- });
260
- },
261
- toBeNull() {
262
- const pass = actual === null;
263
- assertResult({
264
- pass,
265
- message: isNot
266
- ? `Expected ${actual} not to be null`
267
- : `Expected ${actual} to be null`,
268
- });
269
- },
270
- toBeUndefined() {
271
- const pass = actual === undefined;
272
- assertResult({
273
- pass,
274
- message: isNot
275
- ? `Expected ${actual} not to be undefined`
276
- : `Expected ${actual} to be undefined`,
277
- });
278
- },
279
- toBeDefined() {
280
- const pass = actual !== undefined;
281
- assertResult({
282
- pass,
283
- message: isNot
284
- ? `Expected ${actual} not to be defined`
285
- : `Expected ${actual} to be defined`,
286
- });
287
- },
288
- toBeInstanceOf(expected) {
289
- const pass = actual instanceof expected;
290
- assertResult({
291
- pass,
292
- message: isNot
293
- ? `Expected ${actual} not to be instance of ${expected.name}`
294
- : `Expected ${actual} to be instance of ${expected.name}`,
295
- });
296
- },
297
- toContain(expected) {
298
- let pass = false;
299
- if (typeof actual === 'string' && typeof expected === 'string') {
300
- pass = actual.includes(expected);
301
- }
302
- else if (Array.isArray(actual)) {
303
- pass = actual.includes(expected);
304
- }
305
- else if (actual && typeof actual === 'object') {
306
- pass = Object.values(actual).includes(expected);
307
- }
308
- assertResult({
309
- pass,
310
- message: isNot
311
- ? `Expected ${JSON.stringify(actual)} not to contain ${JSON.stringify(expected)}`
312
- : `Expected ${JSON.stringify(actual)} to contain ${JSON.stringify(expected)}`,
313
- });
314
- },
315
- toContainEqual(expected) {
316
- let pass = false;
317
- if (Array.isArray(actual)) {
318
- pass = actual.some((item) => deepEqual(item, expected));
319
- }
320
- else if (actual && typeof actual === 'object') {
321
- pass = Object.values(actual).some((item) => deepEqual(item, expected));
322
- }
323
- assertResult({
324
- pass,
325
- message: isNot
326
- ? `Expected ${JSON.stringify(actual)} not to contain equal ${JSON.stringify(expected)}`
327
- : `Expected ${JSON.stringify(actual)} to contain equal ${JSON.stringify(expected)}`,
328
- });
329
- },
330
- toHaveLength(expected) {
331
- const actualLength = actual?.length;
332
- const pass = actualLength === expected;
333
- assertResult({
334
- pass,
335
- message: isNot
336
- ? `Expected ${JSON.stringify(actual)} not to have length ${expected}`
337
- : `Expected ${JSON.stringify(actual)} to have length ${expected}, but got ${actualLength}`,
338
- });
339
- },
340
- toHaveProperty(keyPath, value) {
341
- const keys = Array.isArray(keyPath) ? keyPath : keyPath.split('.');
342
- let current = actual;
343
- let pass = true;
344
- for (const key of keys) {
345
- if (current == null ||
346
- typeof current !== 'object' ||
347
- !(key in current)) {
348
- pass = false;
349
- break;
350
- }
351
- current = current[key];
352
- }
353
- if (pass && value !== undefined) {
354
- pass = deepEqual(current, value);
355
- }
356
- const keyStr = Array.isArray(keyPath) ? keyPath.join('.') : keyPath;
357
- assertResult({
358
- pass,
359
- message: isNot
360
- ? `Expected ${JSON.stringify(actual)} not to have property "${keyStr}"${value !== undefined ? ` with value ${JSON.stringify(value)}` : ''}`
361
- : `Expected ${JSON.stringify(actual)} to have property "${keyStr}"${value !== undefined ? ` with value ${JSON.stringify(value)}` : ''}`,
362
- });
363
- },
364
- toBeCloseTo(expected, numDigits = 2) {
365
- const actualNum = Number(actual);
366
- const diff = Math.abs(actualNum - expected);
367
- const precision = Math.pow(10, -numDigits) / 2;
368
- const pass = diff < precision;
369
- assertResult({
370
- pass,
371
- message: isNot
372
- ? `Expected ${actualNum} not to be close to ${expected} (precision: ${numDigits} digits)`
373
- : `Expected ${actualNum} to be close to ${expected} (precision: ${numDigits} digits)`,
374
- });
375
- },
376
- toBeGreaterThan(expected) {
377
- const pass = actual > expected;
378
- assertResult({
379
- pass,
380
- message: isNot
381
- ? `Expected ${actual} not to be greater than ${expected}`
382
- : `Expected ${actual} to be greater than ${expected}`,
383
- });
384
- },
385
- toBeGreaterThanOrEqual(expected) {
386
- const pass = actual >= expected;
387
- assertResult({
388
- pass,
389
- message: isNot
390
- ? `Expected ${actual} not to be greater than or equal to ${expected}`
391
- : `Expected ${actual} to be greater than or equal to ${expected}`,
392
- });
393
- },
394
- toBeLessThan(expected) {
395
- const pass = actual < expected;
396
- assertResult({
397
- pass,
398
- message: isNot
399
- ? `Expected ${actual} not to be less than ${expected}`
400
- : `Expected ${actual} to be less than ${expected}`,
401
- });
402
- },
403
- toBeLessThanOrEqual(expected) {
404
- const pass = actual <= expected;
405
- assertResult({
406
- pass,
407
- message: isNot
408
- ? `Expected ${actual} not to be less than or equal to ${expected}`
409
- : `Expected ${actual} to be less than or equal to ${expected}`,
410
- });
411
- },
412
- toBeNaN() {
413
- const pass = Number.isNaN(actual);
414
- assertResult({
415
- pass,
416
- message: isNot
417
- ? `Expected ${actual} not to be NaN`
418
- : `Expected ${actual} to be NaN`,
419
- });
420
- },
421
- toMatch(expected) {
422
- const actualStr = String(actual);
423
- const pass = expected instanceof RegExp
424
- ? expected.test(actualStr)
425
- : actualStr.includes(expected);
426
- assertResult({
427
- pass,
428
- message: isNot
429
- ? `Expected "${actualStr}" not to match ${expected}`
430
- : `Expected "${actualStr}" to match ${expected}`,
431
- });
432
- },
433
- toMatchObject(expected) {
434
- const matchesObject = (actualObj, expectedObj) => {
435
- if (actualObj == null || typeof actualObj !== 'object') {
436
- return false;
437
- }
438
- for (const [key, expectedValue] of Object.entries(expectedObj)) {
439
- const actualValue = actualObj[key];
440
- if (expectedValue &&
441
- typeof expectedValue === 'object' &&
442
- !Array.isArray(expectedValue)) {
443
- if (!matchesObject(actualValue, expectedValue)) {
444
- return false;
445
- }
446
- }
447
- else if (!deepEqual(actualValue, expectedValue)) {
448
- return false;
449
- }
450
- }
451
- return true;
452
- };
453
- const pass = matchesObject(actual, expected);
454
- assertResult({
455
- pass,
456
- message: isNot
457
- ? `Expected ${JSON.stringify(actual)} not to match object ${JSON.stringify(expected)}`
458
- : `Expected ${JSON.stringify(actual)} to match object ${JSON.stringify(expected)}`,
459
- });
460
- },
461
- toThrow(expected) {
462
- let pass = false;
463
- let thrownError = null;
464
- try {
465
- if (typeof actual === 'function') {
466
- actual();
467
- }
468
- }
469
- catch (error) {
470
- thrownError = error;
471
- pass = true;
472
- if (expected) {
473
- if (typeof expected === 'string') {
474
- pass = thrownError.message.includes(expected);
475
- }
476
- else if (expected instanceof RegExp) {
477
- pass = expected.test(thrownError.message);
478
- }
479
- else if (expected instanceof Error) {
480
- pass = thrownError.message === expected.message;
481
- }
482
- }
483
- }
484
- assertResult({
485
- pass,
486
- message: isNot
487
- ? `Expected function not to throw${expected ? ` ${expected}` : ''}`
488
- : `Expected function to throw${expected ? ` ${expected}` : ''}${thrownError ? `, but got: ${thrownError.message}` : ''}`,
489
- });
490
- },
491
- toHaveBeenCalled() {
492
- const mockCalls = actual?.mock
493
- ?.calls;
494
- const pass = Array.isArray(mockCalls) && mockCalls.length > 0;
495
- assertResult({
496
- pass,
497
- message: isNot
498
- ? `Expected spy not to have been called`
499
- : `Expected spy to have been called`,
500
- });
501
- },
502
- toHaveBeenCalledTimes(expected) {
503
- const mockCalls = actual?.mock
504
- ?.calls;
505
- const actualTimes = Array.isArray(mockCalls) ? mockCalls.length : 0;
506
- const pass = actualTimes === expected;
507
- assertResult({
508
- pass,
509
- message: isNot
510
- ? `Expected spy not to have been called ${expected} times`
511
- : `Expected spy to have been called ${expected} times, but was called ${actualTimes} times`,
512
- });
513
- },
514
- toHaveBeenCalledWith(...expected) {
515
- const mockCalls = actual?.mock
516
- ?.calls;
517
- const pass = Array.isArray(mockCalls) &&
518
- mockCalls.some((call) => deepEqual(call, expected));
519
- assertResult({
520
- pass,
521
- message: isNot
522
- ? `Expected spy not to have been called with ${JSON.stringify(expected)}`
523
- : `Expected spy to have been called with ${JSON.stringify(expected)}`,
524
- });
525
- },
526
- toHaveBeenLastCalledWith(...expected) {
527
- const mockCalls = actual?.mock
528
- ?.calls;
529
- const lastCall = Array.isArray(mockCalls)
530
- ? mockCalls[mockCalls.length - 1]
531
- : undefined;
532
- const pass = lastCall ? deepEqual(lastCall, expected) : false;
533
- assertResult({
534
- pass,
535
- message: isNot
536
- ? `Expected spy not to have been last called with ${JSON.stringify(expected)}`
537
- : `Expected spy to have been last called with ${JSON.stringify(expected)}`,
538
- });
539
- },
540
- toHaveBeenNthCalledWith(nthCall, ...expected) {
541
- const mockCalls = actual?.mock
542
- ?.calls;
543
- const call = Array.isArray(mockCalls)
544
- ? mockCalls[nthCall - 1]
545
- : undefined;
546
- const pass = call ? deepEqual(call, expected) : false;
547
- assertResult({
548
- pass,
549
- message: isNot
550
- ? `Expected spy not to have been called the ${nthCall}${nthCall === 1
551
- ? 'st'
552
- : nthCall === 2
553
- ? 'nd'
554
- : nthCall === 3
555
- ? 'rd'
556
- : 'th'} time with ${JSON.stringify(expected)}`
557
- : `Expected spy to have been called the ${nthCall}${nthCall === 1
558
- ? 'st'
559
- : nthCall === 2
560
- ? 'nd'
561
- : nthCall === 3
562
- ? 'rd'
563
- : 'th'} time with ${JSON.stringify(expected)}`,
564
- });
565
- },
566
- toHaveReturned() {
567
- const mockResults = actual?.mock?.results;
568
- const pass = Array.isArray(mockResults) &&
569
- mockResults.some((result) => result.type === 'return');
570
- assertResult({
571
- pass,
572
- message: isNot
573
- ? `Expected spy not to have returned`
574
- : `Expected spy to have returned`,
575
- });
576
- },
577
- toHaveReturnedTimes(expected) {
578
- const mockResults = actual?.mock?.results;
579
- const returnCount = Array.isArray(mockResults)
580
- ? mockResults.filter((result) => result.type === 'return').length
581
- : 0;
582
- const pass = returnCount === expected;
583
- assertResult({
584
- pass,
585
- message: isNot
586
- ? `Expected spy not to have returned ${expected} times`
587
- : `Expected spy to have returned ${expected} times, but returned ${returnCount} times`,
588
- });
589
- },
590
- toHaveReturnedWith(expected) {
591
- const mockResults = actual?.mock?.results;
592
- const pass = Array.isArray(mockResults) &&
593
- mockResults.some((result) => result.type === 'return' && deepEqual(result.value, expected));
594
- assertResult({
595
- pass,
596
- message: isNot
597
- ? `Expected spy not to have returned with ${JSON.stringify(expected)}`
598
- : `Expected spy to have returned with ${JSON.stringify(expected)}`,
599
- });
600
- },
601
- toHaveLastReturnedWith(expected) {
602
- const mockResults = actual?.mock?.results;
603
- const lastReturn = Array.isArray(mockResults)
604
- ? mockResults.filter((result) => result.type === 'return').pop()
605
- : undefined;
606
- const pass = lastReturn ? deepEqual(lastReturn.value, expected) : false;
607
- assertResult({
608
- pass,
609
- message: isNot
610
- ? `Expected spy not to have last returned with ${JSON.stringify(expected)}`
611
- : `Expected spy to have last returned with ${JSON.stringify(expected)}`,
612
- });
613
- },
614
- toHaveNthReturnedWith(nthCall, expected) {
615
- const mockResults = actual?.mock?.results;
616
- const returns = Array.isArray(mockResults)
617
- ? mockResults.filter((result) => result.type === 'return')
618
- : [];
619
- const nthReturn = returns[nthCall - 1];
620
- const pass = nthReturn ? deepEqual(nthReturn.value, expected) : false;
621
- assertResult({
622
- pass,
623
- message: isNot
624
- ? `Expected spy not to have returned the ${nthCall}${nthCall === 1
625
- ? 'st'
626
- : nthCall === 2
627
- ? 'nd'
628
- : nthCall === 3
629
- ? 'rd'
630
- : 'th'} time with ${JSON.stringify(expected)}`
631
- : `Expected spy to have returned the ${nthCall}${nthCall === 1
632
- ? 'st'
633
- : nthCall === 2
634
- ? 'nd'
635
- : nthCall === 3
636
- ? 'rd'
637
- : 'th'} time with ${JSON.stringify(expected)}`,
638
- });
639
- },
640
- };
641
- };
642
- // Asymmetric matcher factory functions
643
- export const asymmetricMatchers = {
644
- anything: () => new AnythingMatcher(),
645
- any: (expectedType) => new AnyMatcher(expectedType),
646
- arrayContaining: (expectedArray) => new ArrayContainingMatcher(expectedArray),
647
- objectContaining: (expectedObject) => new ObjectContainingMatcher(expectedObject),
648
- stringContaining: (expectedString) => new StringContainingMatcher(expectedString),
649
- stringMatching: (expectedPattern) => new StringMatchingMatcher(expectedPattern),
650
- arrayOf: (expectedValue) => new ArrayOfMatcher(expectedValue),
651
- closeTo: (expectedNumber, numDigits) => new CloseToMatcher(expectedNumber, numDigits),
652
- not: {
653
- arrayContaining: (expectedArray) => new NotMatcher(new ArrayContainingMatcher(expectedArray)),
654
- objectContaining: (expectedObject) => new NotMatcher(new ObjectContainingMatcher(expectedObject)),
655
- stringContaining: (expectedString) => new NotMatcher(new StringContainingMatcher(expectedString)),
656
- stringMatching: (expectedPattern) => new NotMatcher(new StringMatchingMatcher(expectedPattern)),
657
- arrayOf: (expectedValue) => new NotMatcher(new ArrayOfMatcher(expectedValue)),
658
- },
659
- };
660
- const expectFn = (actual) => {
661
- const matchers = createMatchers(actual);
662
- const notMatchers = createMatchers(actual, true);
663
- return {
664
- ...matchers,
665
- not: notMatchers,
666
- };
667
- };
668
- export const expect = expectFn;
669
- // Add asymmetric matchers directly to expect function
670
- Object.assign(expect, asymmetricMatchers);
package/dist/rntl/fn.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export { fake } from 'sinon';
2
- //# sourceMappingURL=fn.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fn.d.ts","sourceRoot":"","sources":["../../src/rntl/fn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,OAAO,CAAC"}
package/dist/rntl/fn.js DELETED
@@ -1 +0,0 @@
1
- export { fake } from 'sinon';
@@ -1,2 +0,0 @@
1
- export { mock, requireActual, clearMocks } from '../mock.js';
2
- //# sourceMappingURL=mock.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../src/rntl/mock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
package/dist/rntl/mock.js DELETED
@@ -1 +0,0 @@
1
- export { mock, requireActual, clearMocks } from '../mock.js';
@@ -1,4 +0,0 @@
1
- import { ReactNode } from 'react';
2
- export declare const render: (node: ReactNode, options?: unknown) => Promise<void>;
3
- export declare const cleanup: () => Promise<void>;
4
- //# sourceMappingURL=render.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/rntl/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIlC,eAAO,MAAM,MAAM,GACjB,MAAM,SAAS,EACf,UAAU,OAAO,KAChB,OAAO,CAAC,IAAI,CAId,CAAC;AAEF,eAAO,MAAM,OAAO,QAAa,OAAO,CAAC,IAAI,CAG5C,CAAC"}