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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/.babelrc.js +23 -0
  2. package/LICENSE +20 -0
  3. package/README.md +7 -0
  4. package/assets/logo.png +0 -0
  5. package/assets/moduleSystem.flow.js +1062 -0
  6. package/dist/bundler/bundle.d.ts +2 -0
  7. package/dist/bundler/bundle.d.ts.map +1 -0
  8. package/dist/bundler/bundle.js +16 -0
  9. package/dist/bundler/dev-server.d.ts +2 -0
  10. package/dist/bundler/dev-server.d.ts.map +1 -0
  11. package/dist/bundler/dev-server.js +5 -0
  12. package/dist/bundler/errors.d.ts +10 -0
  13. package/dist/bundler/errors.d.ts.map +1 -0
  14. package/dist/bundler/errors.js +18 -0
  15. package/dist/bundler/evaluate.d.ts +2 -0
  16. package/dist/bundler/evaluate.d.ts.map +1 -0
  17. package/dist/bundler/evaluate.js +18 -0
  18. package/dist/bundler/index.d.ts +3 -0
  19. package/dist/bundler/index.d.ts.map +1 -0
  20. package/dist/bundler/index.js +2 -0
  21. package/dist/client/factory.d.ts +2 -0
  22. package/dist/client/factory.d.ts.map +1 -0
  23. package/dist/client/factory.js +41 -0
  24. package/dist/client/getDeviceDescriptor.d.ts +8 -0
  25. package/dist/client/getDeviceDescriptor.d.ts.map +1 -0
  26. package/dist/client/getDeviceDescriptor.js +20 -0
  27. package/dist/client/getWSServer.d.ts +2 -0
  28. package/dist/client/getWSServer.d.ts.map +1 -0
  29. package/dist/client/getWSServer.js +7 -0
  30. package/dist/client/index.d.ts +2 -0
  31. package/dist/client/index.d.ts.map +1 -0
  32. package/dist/client/index.js +1 -0
  33. package/dist/collector/errors.d.ts +8 -0
  34. package/dist/collector/errors.d.ts.map +1 -0
  35. package/dist/collector/errors.js +20 -0
  36. package/dist/collector/factory.d.ts +3 -0
  37. package/dist/collector/factory.d.ts.map +1 -0
  38. package/dist/collector/factory.js +25 -0
  39. package/dist/collector/functions.d.ts +22 -0
  40. package/dist/collector/functions.d.ts.map +1 -0
  41. package/dist/collector/functions.js +271 -0
  42. package/dist/collector/index.d.ts +5 -0
  43. package/dist/collector/index.d.ts.map +1 -0
  44. package/dist/collector/index.js +3 -0
  45. package/dist/collector/types.d.ts +10 -0
  46. package/dist/collector/types.d.ts.map +1 -0
  47. package/dist/collector/types.js +1 -0
  48. package/dist/collector/validation.d.ts +4 -0
  49. package/dist/collector/validation.d.ts.map +1 -0
  50. package/dist/collector/validation.js +15 -0
  51. package/dist/constants.d.ts +3 -0
  52. package/dist/constants.d.ts.map +1 -0
  53. package/dist/constants.js +2 -0
  54. package/dist/errors.d.ts +6 -0
  55. package/dist/errors.d.ts.map +1 -0
  56. package/dist/errors.js +13 -0
  57. package/dist/expect/index.d.ts +9 -0
  58. package/dist/expect/index.d.ts.map +1 -0
  59. package/dist/expect/index.js +71 -0
  60. package/dist/expect/setup.d.ts +2 -0
  61. package/dist/expect/setup.d.ts.map +1 -0
  62. package/dist/expect/setup.js +5 -0
  63. package/dist/exports.d.ts +7 -0
  64. package/dist/exports.d.ts.map +1 -0
  65. package/dist/exports.js +6 -0
  66. package/dist/getEntryComponent.d.ts +6 -0
  67. package/dist/getEntryComponent.d.ts.map +1 -0
  68. package/dist/getEntryComponent.js +6 -0
  69. package/dist/globals.d.ts +5 -0
  70. package/dist/globals.d.ts.map +1 -0
  71. package/dist/globals.js +1 -0
  72. package/dist/index.d.ts +7 -0
  73. package/dist/index.d.ts.map +1 -0
  74. package/dist/index.js +6 -0
  75. package/dist/initialize.d.ts +2 -0
  76. package/dist/initialize.d.ts.map +1 -0
  77. package/dist/initialize.js +16 -0
  78. package/dist/logger.d.ts +6 -0
  79. package/dist/logger.d.ts.map +1 -0
  80. package/dist/logger.js +14 -0
  81. package/dist/mock.d.ts +15 -0
  82. package/dist/mock.d.ts.map +1 -0
  83. package/dist/mock.js +37 -0
  84. package/dist/mocker/index.d.ts +2 -0
  85. package/dist/mocker/index.d.ts.map +1 -0
  86. package/dist/mocker/index.js +1 -0
  87. package/dist/mocker/registry.d.ts +7 -0
  88. package/dist/mocker/registry.d.ts.map +1 -0
  89. package/dist/mocker/registry.js +41 -0
  90. package/dist/mocker/types.d.ts +6 -0
  91. package/dist/mocker/types.d.ts.map +1 -0
  92. package/dist/mocker/types.js +1 -0
  93. package/dist/module.d.ts +3 -0
  94. package/dist/module.d.ts.map +1 -0
  95. package/dist/module.js +19 -0
  96. package/dist/module.web.d.ts +2 -0
  97. package/dist/module.web.d.ts.map +1 -0
  98. package/dist/module.web.js +12 -0
  99. package/dist/rntl/client.d.ts +3 -0
  100. package/dist/rntl/client.d.ts.map +1 -0
  101. package/dist/rntl/client.js +8 -0
  102. package/dist/rntl/describe.d.ts +2 -0
  103. package/dist/rntl/describe.d.ts.map +1 -0
  104. package/dist/rntl/describe.js +1 -0
  105. package/dist/rntl/expect.d.ts +128 -0
  106. package/dist/rntl/expect.d.ts.map +1 -0
  107. package/dist/rntl/expect.js +670 -0
  108. package/dist/rntl/fn.d.ts +2 -0
  109. package/dist/rntl/fn.d.ts.map +1 -0
  110. package/dist/rntl/fn.js +1 -0
  111. package/dist/rntl/mock.d.ts +2 -0
  112. package/dist/rntl/mock.d.ts.map +1 -0
  113. package/dist/rntl/mock.js +1 -0
  114. package/dist/rntl/render.d.ts +4 -0
  115. package/dist/rntl/render.d.ts.map +1 -0
  116. package/dist/rntl/render.js +11 -0
  117. package/dist/rntl/screen.d.ts +45 -0
  118. package/dist/rntl/screen.d.ts.map +1 -0
  119. package/dist/rntl/screen.js +31 -0
  120. package/dist/rntl/spies.d.ts +45 -0
  121. package/dist/rntl/spies.d.ts.map +1 -0
  122. package/dist/rntl/spies.js +553 -0
  123. package/dist/rntl/userEvent.d.ts +22 -0
  124. package/dist/rntl/userEvent.d.ts.map +1 -0
  125. package/dist/rntl/userEvent.js +19 -0
  126. package/dist/runner/errors.d.ts +9 -0
  127. package/dist/runner/errors.d.ts.map +1 -0
  128. package/dist/runner/errors.js +23 -0
  129. package/dist/runner/factory.d.ts +3 -0
  130. package/dist/runner/factory.d.ts.map +1 -0
  131. package/dist/runner/factory.js +17 -0
  132. package/dist/runner/hooks.d.ts +4 -0
  133. package/dist/runner/hooks.d.ts.map +1 -0
  134. package/dist/runner/hooks.js +39 -0
  135. package/dist/runner/index.d.ts +4 -0
  136. package/dist/runner/index.d.ts.map +1 -0
  137. package/dist/runner/index.js +2 -0
  138. package/dist/runner/runSuite.d.ts +4 -0
  139. package/dist/runner/runSuite.d.ts.map +1 -0
  140. package/dist/runner/runSuite.js +147 -0
  141. package/dist/runner/types.d.ts +13 -0
  142. package/dist/runner/types.d.ts.map +1 -0
  143. package/dist/runner/types.js +1 -0
  144. package/dist/runner.d.ts +7 -0
  145. package/dist/runner.d.ts.map +1 -0
  146. package/dist/runner.js +201 -0
  147. package/dist/runtime.d.ts +2 -0
  148. package/dist/runtime.d.ts.map +1 -0
  149. package/dist/runtime.js +44 -0
  150. package/dist/spy/index.d.ts +2 -0
  151. package/dist/spy/index.d.ts.map +1 -0
  152. package/dist/spy/index.js +2 -0
  153. package/dist/state.d.ts +25 -0
  154. package/dist/state.d.ts.map +1 -0
  155. package/dist/state.js +37 -0
  156. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  157. package/dist/ui/ReadyScreen.d.ts +2 -0
  158. package/dist/ui/ReadyScreen.d.ts.map +1 -0
  159. package/dist/ui/ReadyScreen.js +110 -0
  160. package/dist/ui/UI.d.ts +13 -0
  161. package/dist/ui/UI.d.ts.map +1 -0
  162. package/dist/ui/UI.js +121 -0
  163. package/dist/ui/WrongEnvironmentScreen.d.ts +2 -0
  164. package/dist/ui/WrongEnvironmentScreen.d.ts.map +1 -0
  165. package/dist/ui/WrongEnvironmentScreen.js +87 -0
  166. package/dist/ui/index.d.ts +2 -0
  167. package/dist/ui/index.d.ts.map +1 -0
  168. package/dist/ui/index.js +3 -0
  169. package/dist/ui/state.d.ts +7 -0
  170. package/dist/ui/state.d.ts.map +1 -0
  171. package/dist/ui/state.js +6 -0
  172. package/dist/utils/dev-server.d.ts +2 -0
  173. package/dist/utils/dev-server.d.ts.map +1 -0
  174. package/dist/utils/dev-server.js +5 -0
  175. package/dist/utils/emitter.d.ts +16 -0
  176. package/dist/utils/emitter.d.ts.map +1 -0
  177. package/dist/utils/emitter.js +39 -0
  178. package/eslint.config.mjs +16 -0
  179. package/package.json +38 -0
  180. package/src/__tests__/collector.test.ts +553 -0
  181. package/src/__tests__/error-handling.test.ts +132 -0
  182. package/src/__tests__/expect.test.ts +619 -0
  183. package/src/__tests__/spy.test.ts +538 -0
  184. package/src/bundler/bundle.ts +19 -0
  185. package/src/bundler/errors.ts +16 -0
  186. package/src/bundler/evaluate.ts +25 -0
  187. package/src/bundler/index.ts +2 -0
  188. package/src/client/factory.ts +56 -0
  189. package/src/client/getDeviceDescriptor.ts +30 -0
  190. package/src/client/getWSServer.ts +9 -0
  191. package/src/client/index.ts +1 -0
  192. package/src/collector/errors.ts +27 -0
  193. package/src/collector/factory.ts +32 -0
  194. package/src/collector/functions.ts +376 -0
  195. package/src/collector/index.ts +12 -0
  196. package/src/collector/types.ts +15 -0
  197. package/src/collector/validation.ts +21 -0
  198. package/src/constants.ts +2 -0
  199. package/src/errors.ts +12 -0
  200. package/src/expect/index.ts +117 -0
  201. package/src/expect/setup.ts +10 -0
  202. package/src/globals.ts +5 -0
  203. package/src/index.ts +7 -0
  204. package/src/initialize.ts +22 -0
  205. package/src/mocker/index.ts +1 -0
  206. package/src/mocker/metro-require.d.ts +5 -0
  207. package/src/mocker/registry.ts +58 -0
  208. package/src/mocker/types.ts +6 -0
  209. package/src/react-native.d.ts +16 -0
  210. package/src/runner/errors.ts +31 -0
  211. package/src/runner/factory.ts +21 -0
  212. package/src/runner/hooks.ts +51 -0
  213. package/src/runner/index.ts +7 -0
  214. package/src/runner/runSuite.ts +201 -0
  215. package/src/runner/types.ts +19 -0
  216. package/src/spy/index.ts +2 -0
  217. package/src/ui/ReadyScreen.tsx +151 -0
  218. package/src/ui/WrongEnvironmentScreen.tsx +113 -0
  219. package/src/ui/index.ts +3 -0
  220. package/src/ui/state.ts +13 -0
  221. package/src/utils/dev-server.ts +6 -0
  222. package/src/utils/emitter.ts +64 -0
  223. package/tsconfig.json +16 -0
  224. package/tsconfig.lib.json +33 -0
  225. package/tsconfig.spec.json +30 -0
  226. package/tsconfig.tsbuildinfo +1 -0
  227. package/types/global.d.ts +2 -0
  228. package/types/index.d.ts +1 -0
  229. package/vite.config.ts +27 -0
@@ -0,0 +1,619 @@
1
+ import { describe, test } from 'vitest';
2
+ import { expect } from '../expect/index.js';
3
+
4
+ describe('expect - Basic Matchers', () => {
5
+ describe('toBe', () => {
6
+ test('should pass for identical primitive values', () => {
7
+ expect(1).toBe(1);
8
+ expect('hello').toBe('hello');
9
+ expect(true).toBe(true);
10
+ expect(null).toBe(null);
11
+ expect(undefined).toBe(undefined);
12
+ });
13
+
14
+ test('should fail for different primitive values', () => {
15
+ expect(() => expect(1).toBe(2)).toThrow();
16
+ expect(() => expect('hello').toBe('world')).toThrow();
17
+ expect(() => expect(true).toBe(false)).toThrow();
18
+ });
19
+
20
+ test('should fail for objects with same content', () => {
21
+ expect(() => expect({}).toBe({})).toThrow();
22
+ expect(() => expect([]).toBe([])).toThrow();
23
+ });
24
+ });
25
+
26
+ describe('toEqual', () => {
27
+ test('should pass for equal primitive values', () => {
28
+ expect(1).toEqual(1);
29
+ expect('hello').toEqual('hello');
30
+ expect(true).toEqual(true);
31
+ });
32
+
33
+ test('should pass for equal objects', () => {
34
+ expect({ a: 1, b: 2 }).toEqual({ a: 1, b: 2 });
35
+ expect([1, 2, 3]).toEqual([1, 2, 3]);
36
+ expect({ nested: { value: 'test' } }).toEqual({
37
+ nested: { value: 'test' },
38
+ });
39
+ });
40
+
41
+ test('should fail for unequal objects', () => {
42
+ expect(() => expect({ a: 1 }).toEqual({ a: 2 })).toThrow();
43
+ expect(() => expect([1, 2]).toEqual([1, 3])).toThrow();
44
+ });
45
+ });
46
+
47
+ describe('toStrictEqual', () => {
48
+ test('should pass for strictly equal values', () => {
49
+ expect({ a: 1 }).toStrictEqual({ a: 1 });
50
+ expect([1, 2, 3]).toStrictEqual([1, 2, 3]);
51
+ });
52
+
53
+ test('should fail for objects with undefined vs missing properties', () => {
54
+ expect(() =>
55
+ expect({ a: 1, b: undefined }).toStrictEqual({ a: 1 })
56
+ ).toThrow();
57
+ });
58
+
59
+ test('should differentiate between sparse and dense arrays', () => {
60
+ const sparse = [1, , 3]; // eslint-disable-line no-sparse-arrays
61
+ const dense = [1, undefined, 3];
62
+ expect(() => expect(sparse).toStrictEqual(dense)).toThrow();
63
+ });
64
+ });
65
+ });
66
+
67
+ describe('expect - Truthiness', () => {
68
+ describe('toBeTruthy', () => {
69
+ test('should pass for truthy values', () => {
70
+ expect(true).toBeTruthy();
71
+ expect(1).toBeTruthy();
72
+ expect('hello').toBeTruthy();
73
+ expect({}).toBeTruthy();
74
+ expect([]).toBeTruthy();
75
+ expect(function () {}).toBeTruthy();
76
+ });
77
+
78
+ test('should fail for falsy values', () => {
79
+ expect(() => expect(false).toBeTruthy()).toThrow();
80
+ expect(() => expect(0).toBeTruthy()).toThrow();
81
+ expect(() => expect('').toBeTruthy()).toThrow();
82
+ expect(() => expect(null).toBeTruthy()).toThrow();
83
+ expect(() => expect(undefined).toBeTruthy()).toThrow();
84
+ expect(() => expect(NaN).toBeTruthy()).toThrow();
85
+ });
86
+ });
87
+
88
+ describe('toBeFalsy', () => {
89
+ test('should pass for falsy values', () => {
90
+ expect(false).toBeFalsy();
91
+ expect(0).toBeFalsy();
92
+ expect('').toBeFalsy();
93
+ expect(null).toBeFalsy();
94
+ expect(undefined).toBeFalsy();
95
+ expect(NaN).toBeFalsy();
96
+ });
97
+
98
+ test('should fail for truthy values', () => {
99
+ expect(() => expect(true).toBeFalsy()).toThrow();
100
+ expect(() => expect(1).toBeFalsy()).toThrow();
101
+ expect(() => expect('hello').toBeFalsy()).toThrow();
102
+ });
103
+ });
104
+ });
105
+
106
+ describe('expect - Numbers', () => {
107
+ describe('toBeGreaterThan', () => {
108
+ test('should pass when value is greater', () => {
109
+ expect(5).toBeGreaterThan(3);
110
+ expect(0).toBeGreaterThan(-1);
111
+ expect(1.5).toBeGreaterThan(1.4);
112
+ });
113
+
114
+ test('should fail when value is equal or less', () => {
115
+ expect(() => expect(3).toBeGreaterThan(5)).toThrow();
116
+ expect(() => expect(3).toBeGreaterThan(3)).toThrow();
117
+ });
118
+ });
119
+
120
+ describe('toBeGreaterThanOrEqual', () => {
121
+ test('should pass when value is greater or equal', () => {
122
+ expect(5).toBeGreaterThanOrEqual(3);
123
+ expect(3).toBeGreaterThanOrEqual(3);
124
+ expect(0).toBeGreaterThanOrEqual(-1);
125
+ });
126
+
127
+ test('should fail when value is less', () => {
128
+ expect(() => expect(3).toBeGreaterThanOrEqual(5)).toThrow();
129
+ });
130
+ });
131
+
132
+ describe('toBeLessThan', () => {
133
+ test('should pass when value is less', () => {
134
+ expect(3).toBeLessThan(5);
135
+ expect(-1).toBeLessThan(0);
136
+ expect(1.4).toBeLessThan(1.5);
137
+ });
138
+
139
+ test('should fail when value is equal or greater', () => {
140
+ expect(() => expect(5).toBeLessThan(3)).toThrow();
141
+ expect(() => expect(3).toBeLessThan(3)).toThrow();
142
+ });
143
+ });
144
+
145
+ describe('toBeLessThanOrEqual', () => {
146
+ test('should pass when value is less or equal', () => {
147
+ expect(3).toBeLessThanOrEqual(5);
148
+ expect(3).toBeLessThanOrEqual(3);
149
+ expect(-1).toBeLessThanOrEqual(0);
150
+ });
151
+
152
+ test('should fail when value is greater', () => {
153
+ expect(() => expect(5).toBeLessThanOrEqual(3)).toThrow();
154
+ });
155
+ });
156
+
157
+ describe('toBeCloseTo', () => {
158
+ test('should pass for values close to each other', () => {
159
+ expect(0.2 + 0.1).toBeCloseTo(0.3);
160
+ expect(0.2 + 0.1).toBeCloseTo(0.3, 5);
161
+ });
162
+
163
+ test('should fail for values far apart', () => {
164
+ expect(() => expect(0.1).toBeCloseTo(0.2)).toThrow();
165
+ });
166
+
167
+ test('should respect precision parameter', () => {
168
+ expect(1.23456).toBeCloseTo(1.23, 2);
169
+ expect(() => expect(1.23456).toBeCloseTo(1.23, 4)).toThrow();
170
+ });
171
+ });
172
+
173
+ describe('toBeNaN', () => {
174
+ test('should pass for NaN', () => {
175
+ expect(NaN).toBeNaN();
176
+ expect(Number('not a number')).toBeNaN();
177
+ expect(0 / 0).toBeNaN();
178
+ });
179
+
180
+ test('should fail for numbers', () => {
181
+ expect(() => expect(1).toBeNaN()).toThrow();
182
+ expect(() => expect(0).toBeNaN()).toThrow();
183
+ expect(() => expect(Infinity).toBeNaN()).toThrow();
184
+ });
185
+ });
186
+ });
187
+
188
+ describe('expect - Strings', () => {
189
+ describe('toMatch', () => {
190
+ test('should pass for matching strings', () => {
191
+ expect('hello world').toMatch('world');
192
+ expect('hello world').toMatch(/world/);
193
+ expect('hello world').toMatch(/^hello/);
194
+ });
195
+
196
+ test('should fail for non-matching strings', () => {
197
+ expect(() => expect('hello world').toMatch('xyz')).toThrow();
198
+ expect(() => expect('hello world').toMatch(/xyz/)).toThrow();
199
+ });
200
+ });
201
+
202
+ describe('toContain', () => {
203
+ test('should pass for strings containing substring', () => {
204
+ expect('hello world').toContain('world');
205
+ expect('hello world').toContain('hello');
206
+ expect('hello world').toContain(' ');
207
+ });
208
+
209
+ test('should fail for strings not containing substring', () => {
210
+ expect(() => expect('hello world').toContain('xyz')).toThrow();
211
+ });
212
+ });
213
+
214
+ describe('toHaveLength', () => {
215
+ test('should pass for correct string length', () => {
216
+ expect('hello').toHaveLength(5);
217
+ expect('').toHaveLength(0);
218
+ });
219
+
220
+ test('should fail for incorrect string length', () => {
221
+ expect(() => expect('hello').toHaveLength(3)).toThrow();
222
+ });
223
+ });
224
+ });
225
+
226
+ describe('expect - Arrays and Iterables', () => {
227
+ describe('toContain for arrays', () => {
228
+ test('should pass for arrays containing value', () => {
229
+ expect([1, 2, 3]).toContain(2);
230
+ expect(['a', 'b', 'c']).toContain('b');
231
+ });
232
+
233
+ test('should fail for arrays not containing value', () => {
234
+ expect(() => expect([1, 2, 3]).toContain(4)).toThrow();
235
+ });
236
+ });
237
+
238
+ describe('toContainEqual', () => {
239
+ test('should pass for arrays containing equal object', () => {
240
+ expect([{ id: 1 }, { id: 2 }]).toContainEqual({ id: 1 });
241
+ expect([
242
+ [1, 2],
243
+ [3, 4],
244
+ ]).toContainEqual([1, 2]);
245
+ });
246
+
247
+ test('should fail for arrays not containing equal object', () => {
248
+ expect(() => expect([{ id: 1 }]).toContainEqual({ id: 2 })).toThrow();
249
+ });
250
+ });
251
+
252
+ describe('toHaveLength for arrays', () => {
253
+ test('should pass for correct array length', () => {
254
+ expect([1, 2, 3]).toHaveLength(3);
255
+ expect([]).toHaveLength(0);
256
+ });
257
+
258
+ test('should fail for incorrect array length', () => {
259
+ expect(() => expect([1, 2, 3]).toHaveLength(2)).toThrow();
260
+ });
261
+ });
262
+ });
263
+
264
+ describe('expect - Objects', () => {
265
+ describe('toHaveProperty', () => {
266
+ test('should pass for existing properties', () => {
267
+ const obj = { a: 1, b: { c: 2 } };
268
+ expect(obj).toHaveProperty('a');
269
+ expect(obj).toHaveProperty('b.c');
270
+ expect(obj).toHaveProperty(['b', 'c']);
271
+ });
272
+
273
+ test('should pass for existing properties with values', () => {
274
+ const obj = { a: 1, b: { c: 2 } };
275
+ expect(obj).toHaveProperty('a', 1);
276
+ expect(obj).toHaveProperty('b.c', 2);
277
+ });
278
+
279
+ test('should fail for non-existing properties', () => {
280
+ const obj = { a: 1 };
281
+ expect(() => expect(obj).toHaveProperty('b')).toThrow();
282
+ expect(() => expect(obj).toHaveProperty('a.b')).toThrow();
283
+ });
284
+
285
+ test('should fail for wrong property values', () => {
286
+ const obj = { a: 1 };
287
+ expect(() => expect(obj).toHaveProperty('a', 2)).toThrow();
288
+ });
289
+ });
290
+
291
+ describe('toMatchObject', () => {
292
+ test('should pass for matching object subset', () => {
293
+ const obj = { a: 1, b: 2, c: 3 };
294
+ expect(obj).toMatchObject({ a: 1, b: 2 });
295
+ expect(obj).toMatchObject({ a: 1 });
296
+ });
297
+
298
+ test('should pass for nested object matching', () => {
299
+ const obj = { a: { b: { c: 1 } }, d: 2 };
300
+ expect(obj).toMatchObject({ a: { b: { c: 1 } } });
301
+ });
302
+
303
+ test('should fail for non-matching properties', () => {
304
+ const obj = { a: 1, b: 2 };
305
+ expect(() => expect(obj).toMatchObject({ a: 2 })).toThrow();
306
+ expect(() => expect(obj).toMatchObject({ c: 3 })).toThrow();
307
+ });
308
+ });
309
+ });
310
+
311
+ describe('expect - Type Checking', () => {
312
+ describe('toBeInstanceOf', () => {
313
+ test('should pass for correct instances', () => {
314
+ expect(new Date()).toBeInstanceOf(Date);
315
+ expect([]).toBeInstanceOf(Array);
316
+ expect(new Error()).toBeInstanceOf(Error);
317
+ expect(/regex/).toBeInstanceOf(RegExp);
318
+ });
319
+
320
+ test('should fail for incorrect instances', () => {
321
+ expect(() => expect('string').toBeInstanceOf(Date)).toThrow();
322
+ expect(() => expect(123).toBeInstanceOf(String)).toThrow();
323
+ });
324
+ });
325
+
326
+ describe('toBeTypeOf', () => {
327
+ test('should pass for correct types', () => {
328
+ expect('hello').toBeTypeOf('string');
329
+ expect(123).toBeTypeOf('number');
330
+ expect(true).toBeTypeOf('boolean');
331
+ expect(undefined).toBeTypeOf('undefined');
332
+ expect(Symbol('test')).toBeTypeOf('symbol');
333
+ expect(() => {}).toBeTypeOf('function');
334
+ expect({}).toBeTypeOf('object');
335
+ });
336
+
337
+ test('should fail for incorrect types', () => {
338
+ expect(() => expect('hello').toBeTypeOf('number')).toThrow();
339
+ expect(() => expect(123).toBeTypeOf('string')).toThrow();
340
+ });
341
+ });
342
+
343
+ describe('toBeDefined', () => {
344
+ test('should pass for defined values', () => {
345
+ expect(0).toBeDefined();
346
+ expect('').toBeDefined();
347
+ expect(false).toBeDefined();
348
+ expect(null).toBeDefined();
349
+ expect({}).toBeDefined();
350
+ });
351
+
352
+ test('should fail for undefined', () => {
353
+ expect(() => expect(undefined).toBeDefined()).toThrow();
354
+ });
355
+ });
356
+
357
+ describe('toBeUndefined', () => {
358
+ test('should pass for undefined', () => {
359
+ expect(undefined).toBeUndefined();
360
+ let uninitialized;
361
+ expect(uninitialized).toBeUndefined();
362
+ });
363
+
364
+ test('should fail for defined values', () => {
365
+ expect(() => expect(null).toBeUndefined()).toThrow();
366
+ expect(() => expect(0).toBeUndefined()).toThrow();
367
+ });
368
+ });
369
+
370
+ describe('toBeNull', () => {
371
+ test('should pass for null', () => {
372
+ expect(null).toBeNull();
373
+ });
374
+
375
+ test('should fail for non-null values', () => {
376
+ expect(() => expect(undefined).toBeNull()).toThrow();
377
+ expect(() => expect(0).toBeNull()).toThrow();
378
+ });
379
+ });
380
+ });
381
+
382
+ describe('expect - Exceptions', () => {
383
+ describe('toThrow', () => {
384
+ test('should pass for functions that throw', () => {
385
+ expect(() => {
386
+ throw new Error('test error');
387
+ }).toThrow();
388
+
389
+ expect(() => {
390
+ throw new Error('test error');
391
+ }).toThrow('test error');
392
+
393
+ expect(() => {
394
+ throw new Error('test error');
395
+ }).toThrow(/test/);
396
+ });
397
+
398
+ test('should pass for specific error types', () => {
399
+ expect(() => {
400
+ throw new TypeError('type error');
401
+ }).toThrow(TypeError);
402
+
403
+ expect(() => {
404
+ throw new RangeError('range error');
405
+ }).toThrow(RangeError);
406
+ });
407
+
408
+ test('should fail for functions that do not throw', () => {
409
+ expect(() => expect(() => {}).toThrow()).toThrow();
410
+ });
411
+
412
+ test('should fail for wrong error message', () => {
413
+ expect(() => {
414
+ expect(() => {
415
+ throw new Error('actual message');
416
+ }).toThrow('expected message');
417
+ }).toThrow();
418
+ });
419
+
420
+ test('should fail for wrong error type', () => {
421
+ expect(() => {
422
+ expect(() => {
423
+ throw new Error('test');
424
+ }).toThrow(TypeError);
425
+ }).toThrow();
426
+ });
427
+ });
428
+
429
+ describe('toThrowError', () => {
430
+ test('should be alias for toThrow', () => {
431
+ expect(() => {
432
+ throw new Error('test');
433
+ }).toThrowError();
434
+
435
+ expect(() => {
436
+ throw new Error('test');
437
+ }).toThrowError('test');
438
+ });
439
+ });
440
+ });
441
+
442
+ describe('expect - Asymmetric Matchers', () => {
443
+ describe('expect.any', () => {
444
+ test('should match any instance of constructor', () => {
445
+ expect('hello').toEqual(expect.any(String));
446
+ expect(123).toEqual(expect.any(Number));
447
+ expect({}).toEqual(expect.any(Object));
448
+ expect([]).toEqual(expect.any(Array));
449
+ expect(new Date()).toEqual(expect.any(Date));
450
+ });
451
+
452
+ test('should work in object matching', () => {
453
+ expect({ id: 1, name: 'test' }).toEqual({
454
+ id: expect.any(Number),
455
+ name: expect.any(String),
456
+ });
457
+ });
458
+ });
459
+
460
+ describe('expect.anything', () => {
461
+ test('should match any defined value', () => {
462
+ expect('hello').toEqual(expect.anything());
463
+ expect(123).toEqual(expect.anything());
464
+ expect({}).toEqual(expect.anything());
465
+ expect([]).toEqual(expect.anything());
466
+ });
467
+
468
+ test('should not match undefined', () => {
469
+ expect(() => expect(undefined).toEqual(expect.anything())).toThrow();
470
+ });
471
+ });
472
+
473
+ describe('expect.arrayContaining', () => {
474
+ test('should match arrays containing all specified elements', () => {
475
+ expect([1, 2, 3, 4]).toEqual(expect.arrayContaining([2, 3]));
476
+ expect(['a', 'b', 'c']).toEqual(expect.arrayContaining(['b']));
477
+ });
478
+
479
+ test('should fail when array does not contain all elements', () => {
480
+ expect(() =>
481
+ expect([1, 2, 3]).toEqual(expect.arrayContaining([4, 5]))
482
+ ).toThrow();
483
+ });
484
+ });
485
+
486
+ describe('expect.objectContaining', () => {
487
+ test('should match objects containing specified properties', () => {
488
+ expect({ a: 1, b: 2, c: 3 }).toEqual(
489
+ expect.objectContaining({ a: 1, b: 2 })
490
+ );
491
+ expect({ name: 'test', id: 1 }).toEqual(
492
+ expect.objectContaining({ name: 'test' })
493
+ );
494
+ });
495
+
496
+ test('should fail when object does not contain specified properties', () => {
497
+ expect(() =>
498
+ expect({ a: 1 }).toEqual(expect.objectContaining({ b: 2 }))
499
+ ).toThrow();
500
+ });
501
+ });
502
+
503
+ describe('expect.stringContaining', () => {
504
+ test('should match strings containing substring', () => {
505
+ expect('hello world').toEqual(expect.stringContaining('world'));
506
+ expect('hello world').toEqual(expect.stringContaining('hello'));
507
+ });
508
+
509
+ test('should fail when string does not contain substring', () => {
510
+ expect(() =>
511
+ expect('hello world').toEqual(expect.stringContaining('xyz'))
512
+ ).toThrow();
513
+ });
514
+ });
515
+
516
+ describe('expect.stringMatching', () => {
517
+ test('should match strings matching regex', () => {
518
+ expect('hello world').toEqual(expect.stringMatching(/world/));
519
+ expect('hello world').toEqual(expect.stringMatching('world'));
520
+ });
521
+
522
+ test('should fail when string does not match pattern', () => {
523
+ expect(() =>
524
+ expect('hello world').toEqual(expect.stringMatching(/xyz/))
525
+ ).toThrow();
526
+ });
527
+ });
528
+ });
529
+
530
+ describe('expect - Negation', () => {
531
+ test('should negate basic matchers with .not', () => {
532
+ expect(1).not.toBe(2);
533
+ expect('hello').not.toEqual('world');
534
+ expect([1, 2, 3]).not.toContain(4);
535
+ expect({ a: 1 }).not.toHaveProperty('b');
536
+ });
537
+
538
+ test('should negate truthiness', () => {
539
+ expect(false).not.toBeTruthy();
540
+ expect(true).not.toBeFalsy();
541
+ expect(0).not.toBeTruthy();
542
+ });
543
+
544
+ test('should negate type checks', () => {
545
+ expect('string').not.toBeTypeOf('number');
546
+ expect(undefined).not.toBeDefined();
547
+ expect(123).not.toBeUndefined();
548
+ });
549
+ });
550
+
551
+ describe('expect - Custom Messages', () => {
552
+ test('should support custom error messages', () => {
553
+ expect(() => {
554
+ expect(1, 'This is a custom message').toBe(2);
555
+ }).toThrow('This is a custom message');
556
+ });
557
+ });
558
+
559
+ describe('expect - Edge Cases', () => {
560
+ test('should handle circular references', () => {
561
+ const circular: any = { a: 1 };
562
+ circular.self = circular;
563
+
564
+ const circular2: any = { a: 1 };
565
+ circular2.self = circular2;
566
+
567
+ expect(circular).toEqual(circular2);
568
+ });
569
+
570
+ test('should handle sparse arrays', () => {
571
+ const sparse1 = [1, , 3]; // eslint-disable-line no-sparse-arrays
572
+ const sparse2 = [1, , 3]; // eslint-disable-line no-sparse-arrays
573
+ expect(sparse1).toEqual(sparse2);
574
+ });
575
+
576
+ test('should handle special number values', () => {
577
+ expect(Infinity).toBe(Infinity);
578
+ expect(-Infinity).toBe(-Infinity);
579
+ expect(0).toBe(0);
580
+ expect(-0).toBe(-0);
581
+ });
582
+
583
+ test('should handle Date objects', () => {
584
+ const date1 = new Date('2023-01-01');
585
+ const date2 = new Date('2023-01-01');
586
+ expect(date1).toEqual(date2);
587
+ expect(date1).not.toBe(date2);
588
+ });
589
+
590
+ test('should handle RegExp objects', () => {
591
+ expect(/abc/g).toEqual(/abc/g);
592
+ expect(/abc/g).not.toBe(/abc/g);
593
+ });
594
+
595
+ test('should handle Symbol primitives', () => {
596
+ const sym1 = Symbol('test');
597
+ const sym2 = Symbol('test');
598
+ expect(sym1).toBe(sym1);
599
+ expect(sym1).not.toBe(sym2);
600
+ });
601
+
602
+ test('should handle Map objects', () => {
603
+ const map1 = new Map([
604
+ ['a', 1],
605
+ ['b', 2],
606
+ ]);
607
+ const map2 = new Map([
608
+ ['a', 1],
609
+ ['b', 2],
610
+ ]);
611
+ expect(map1).toEqual(map2);
612
+ });
613
+
614
+ test('should handle Set objects', () => {
615
+ const set1 = new Set([1, 2, 3]);
616
+ const set2 = new Set([1, 2, 3]);
617
+ expect(set1).toEqual(set2);
618
+ });
619
+ });