@trackunit/react-test-setup 1.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/index.cjs.js ADDED
@@ -0,0 +1,680 @@
1
+ 'use strict';
2
+
3
+ var failOnConsole = require('jest-fail-on-console');
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+ var reactGoogleMaps = require('@vis.gl/react-google-maps');
6
+ var jestMocks = require('@googlemaps/jest-mocks');
7
+ require('@testing-library/jest-dom');
8
+ var react = require('@testing-library/react');
9
+ var polyfill = require('@js-temporal/polyfill');
10
+ var web = require('@react-spring/web');
11
+
12
+ /**
13
+ * Sets up a mock implementation for HTML Canvas API in testing environments.
14
+ *
15
+ * This function uses jest-canvas-mock to provide a mock implementation of the
16
+ * HTML Canvas API, allowing tests to run without requiring a real DOM canvas.
17
+ * Useful for testing components that use canvas rendering.
18
+ *
19
+ * @example
20
+ * // In your jest setup file
21
+ * import { setupCanvasMock } from '@trackunit/react-test-setup';
22
+ *
23
+ * setupCanvasMock();
24
+ */
25
+ const setupCanvasMock = () => {
26
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
27
+ require("jest-canvas-mock");
28
+ };
29
+
30
+ /**
31
+ * This will make your tests fail if they log to console.error during the tests.
32
+ * See more details here: https://www.npmjs.com/package/jest-fail-on-console
33
+ *
34
+ * If your tests logs to console.error on purpose, you should spy on the console like so:
35
+ * ```
36
+ * jest.spyOn(console, 'error').mockImplementation()
37
+ * // Do your logic ...
38
+ * expect(console.error).toHaveBeenCalledWith('your error message')
39
+ * ```
40
+ */
41
+ const setupFailOnConsole = (overrides = {}) => {
42
+ failOnConsole({
43
+ shouldFailOnError: true,
44
+ shouldFailOnWarn: false,
45
+ ...overrides,
46
+ });
47
+ };
48
+
49
+ const getPlacePredictionsMock = jest.fn();
50
+ /**
51
+ * Sets up mocks for Google Maps API and @vis.gl/react-google-maps components in testing environments.
52
+ *
53
+ * This function mocks both the Google Maps JavaScript API and React components from @vis.gl/react-google-maps.
54
+ * It provides mock implementations of Maps, Markers, Geocoder, geometry functions, and places services,
55
+ * allowing tests of map-dependent components to run without requiring the actual Google Maps API.
56
+ *
57
+ * Key features:
58
+ * - Mocks core Map and Marker components with simple test-friendly implementations
59
+ * - Provides placeholders for Google Maps geometry calculations
60
+ * - Stubs out Places API services
61
+ * - Makes map-related hooks always return loaded state
62
+ *
63
+ * @example
64
+ * // In your jest setup file
65
+ * import { setupGoogleMaps } from '@trackunit/react-test-setup';
66
+ *
67
+ * setupGoogleMaps();
68
+ */
69
+ const setupGoogleMaps = () => {
70
+ //To create @vis.gl/react-google-maps mock, the initialization needs to be called
71
+ jestMocks.initialize();
72
+ jest.mock("@vis.gl/react-google-maps", () => {
73
+ const originalModule = jest.requireActual("@vis.gl/react-google-maps");
74
+ const mapOptions = { mapId: "Map 1" };
75
+ const map = new google.maps.Map(document.createElement("div"), mapOptions);
76
+ const AdvancedMarkerMock = jest.fn(props => {
77
+ return (jsxRuntime.jsx("div", { "data-position": JSON.stringify(props.position), "data-testid": "marker", children: props.children }));
78
+ });
79
+ const MapMock = jest.fn(props => {
80
+ return jsxRuntime.jsx("div", { "data-testid": "map", children: props.children });
81
+ });
82
+ const MapMarkerMock = jest.fn(props => {
83
+ return jsxRuntime.jsx("div", { "data-testid": "map", children: props.children });
84
+ });
85
+ return {
86
+ ...originalModule,
87
+ useApiLoadingStatus: () => reactGoogleMaps.APILoadingStatus.LOADED,
88
+ useApiIsLoaded: () => true,
89
+ useMap: () => map,
90
+ AdvancedMarker: AdvancedMarkerMock,
91
+ Map: MapMock,
92
+ Marker: MapMarkerMock,
93
+ };
94
+ });
95
+ beforeEach(() => {
96
+ jestMocks.initialize();
97
+ //Adding extras
98
+ global.window.google.maps = {
99
+ ...global.window.google.maps,
100
+ Geocoder: jest.fn(),
101
+ geometry: {
102
+ ...global.window.google.maps.geometry,
103
+ spherical: {
104
+ computeDistanceBetween: jest.fn(),
105
+ computeArea: jest.fn(),
106
+ computeHeading: jest.fn(),
107
+ computeLength: jest.fn(),
108
+ computeOffset: jest.fn(),
109
+ computeOffsetOrigin: jest.fn(),
110
+ computeSignedArea: jest.fn(),
111
+ interpolate: jest.fn(),
112
+ },
113
+ },
114
+ places: {
115
+ ...global.window.google.maps.places,
116
+ AutocompleteService: jest.fn().mockImplementation(() => ({
117
+ ...global.window.google.maps.places,
118
+ getPlacePredictions: getPlacePredictionsMock,
119
+ })),
120
+ },
121
+ };
122
+ });
123
+ };
124
+
125
+ /**
126
+ * Mock helmet module
127
+ * See more details here: https://www.npmjs.com/package/react-helmet-async
128
+ */
129
+ const setupHelmetMock = () => {
130
+ jest.mock("react-helmet-async", () => ({
131
+ Helmet: () => null,
132
+ HelmetProvider: () => null,
133
+ }));
134
+ };
135
+
136
+ /* eslint-disable @typescript-eslint/explicit-member-accessibility */
137
+ /**
138
+ * Mocks the IntersectionObserver API for testing environments.
139
+ *
140
+ * This function adds a mock implementation of the IntersectionObserver API to the global window object.
141
+ * The mock implementation provides all the necessary methods (observe, unobserve, disconnect, takeRecords)
142
+ * but with empty implementations, allowing tests of components that use IntersectionObserver to run
143
+ * without errors in Jest's JSDOM environment.
144
+ *
145
+ * Useful for testing components that rely on:
146
+ * - Lazy loading
147
+ * - Infinite scrolling
148
+ * - Visibility-based rendering
149
+ * - Any other intersection-based functionality
150
+ *
151
+ * @example
152
+ * // In your jest setup file
153
+ * import { setupIntersectionObserver } from '@trackunit/react-test-setup';
154
+ *
155
+ * setupIntersectionObserver();
156
+ */
157
+ const setupIntersectionObserver = () => (window.IntersectionObserver = MockIntersectionObserver);
158
+ class MockIntersectionObserver {
159
+ constructor() {
160
+ this.root = null;
161
+ this.rootMargin = "";
162
+ this.thresholds = [];
163
+ }
164
+ disconnect() {
165
+ // Empty
166
+ }
167
+ observe() {
168
+ // Empty
169
+ }
170
+ takeRecords() {
171
+ return [];
172
+ }
173
+ unobserve() {
174
+ // Empty
175
+ }
176
+ }
177
+
178
+ /**
179
+ * Mocks the window.matchMedia API for testing environments.
180
+ *
181
+ * This function creates a mock implementation of the window.matchMedia method that
182
+ * is commonly used for responsive design and media queries. The mock always returns
183
+ * a MediaQueryList-like object with standard methods and properties, but with default
184
+ * values (matches set to false).
185
+ *
186
+ * This allows tests of components that use media queries to run without errors in
187
+ * Jest's JSDOM environment, which doesn't implement matchMedia natively.
188
+ *
189
+ * Ideal for testing:
190
+ * - Responsive components
191
+ * - Components that adapt to screen size changes
192
+ * - Components that use CSS media query matching in JavaScript
193
+ *
194
+ * @example
195
+ * // In your jest setup file
196
+ * import { setupMatchMediaMock } from '@trackunit/react-test-setup';
197
+ *
198
+ * setupMatchMediaMock();
199
+ */
200
+ const setupMatchMediaMock = () => {
201
+ Object.defineProperty(window, "matchMedia", {
202
+ writable: true,
203
+ value: jest.fn().mockImplementation(query => ({
204
+ matches: false,
205
+ media: query,
206
+ onchange: null,
207
+ addListener: jest.fn(), // Deprecated
208
+ removeListener: jest.fn(), // Deprecated
209
+ addEventListener: jest.fn(),
210
+ removeEventListener: jest.fn(),
211
+ dispatchEvent: jest.fn(),
212
+ })),
213
+ });
214
+ };
215
+
216
+ /**
217
+ * Flushes all promises in the queue.
218
+ * This is useful when testing async code.
219
+ *
220
+ * @param waitTimeInMS - The amount of time to wait before resolving the promise.
221
+ * @returns {Promise<void>} - Returns a promise that resolves after the wait time.
222
+ */
223
+ const flushPromisesInAct = (waitTimeInMS = 0) => {
224
+ return react.act(() => {
225
+ return new Promise(resolve => {
226
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
227
+ if (global.ORG_setTimeout) {
228
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
229
+ return global.ORG_setTimeout(() => global.ORG_setTimeout(resolve, waitTimeInMS), 1);
230
+ }
231
+ else {
232
+ setTimeout(() => setTimeout(resolve, waitTimeInMS), 1);
233
+ }
234
+ });
235
+ });
236
+ };
237
+ afterEach(async () => {
238
+ jest.clearAllMocks();
239
+ react.cleanup();
240
+ await flushPromisesInAct();
241
+ });
242
+ /**
243
+ * Sets up React Testing Library and Okta authentication mocks for testing.
244
+ *
245
+ * This function configures the testing environment with essential mocks for Okta authentication,
246
+ * which is necessary for testing components that use Okta for authentication. It creates
247
+ * mock implementations of Okta authentication objects, tokens, and authentication state,
248
+ * allowing tests to run without requiring an actual Okta authentication flow.
249
+ *
250
+ * The module also imports @testing-library/jest-dom to extend Jest with DOM testing assertions
251
+ * and sets up afterEach hooks to clear mocks and clean up after each test.
252
+ *
253
+ * Key features:
254
+ * - Mocks Okta tokens and authentication state
255
+ * - Creates mock implementations of Okta auth methods
256
+ * - Extends Jest with DOM testing assertions
257
+ * - Automatically cleans up after each test
258
+ *
259
+ * @example
260
+ * // In your jest setup file
261
+ * import { setupReactTestingLibrary } from '@trackunit/react-test-setup';
262
+ *
263
+ * setupReactTestingLibrary();
264
+ */
265
+ const setupReactTestingLibrary = () => {
266
+ const mockedClaims = {
267
+ sub: "sub",
268
+ name: "user",
269
+ };
270
+ const mockedIdToken = {
271
+ idToken: "idToken",
272
+ claims: mockedClaims,
273
+ expiresAt: Date.now(),
274
+ authorizeUrl: "authorize.url",
275
+ scopes: [],
276
+ issuer: "issuer",
277
+ clientId: "clientId",
278
+ };
279
+ const mockedAccessToken = {
280
+ accessToken: "accessToken",
281
+ claims: mockedClaims,
282
+ tokenType: "tokenType",
283
+ userinfoUrl: "userinfo.url",
284
+ expiresAt: Date.now(),
285
+ authorizeUrl: "authorize.url",
286
+ scopes: [],
287
+ };
288
+ const mockedAuthState = {
289
+ accessToken: mockedAccessToken,
290
+ idToken: mockedIdToken,
291
+ isAuthenticated: true,
292
+ };
293
+ const mockedOktaAuth = () => {
294
+ return {
295
+ oktaAuth: {
296
+ tokenManager: {
297
+ on: jest.fn(),
298
+ renew: jest.fn(),
299
+ setTokens: jest.fn(),
300
+ clear: jest.fn(),
301
+ },
302
+ getOriginalUri: jest.fn(),
303
+ signOut: jest.fn().mockResolvedValue({ postLogoutRedirectUri: "mocked-url", clearTokensBeforeRedirect: true }),
304
+ token: {
305
+ getWithRedirect: jest.fn(),
306
+ getWithoutPrompt: jest.fn(),
307
+ },
308
+ session: {
309
+ get: () => {
310
+ return { status: "ACTIVE" };
311
+ },
312
+ },
313
+ authStateManager: {
314
+ getAuthState: jest.fn(),
315
+ subscribe: jest.fn(),
316
+ unsubscribe: jest.fn(),
317
+ },
318
+ closeSession: jest.fn(),
319
+ options: {
320
+ restoreOriginalUri: "",
321
+ },
322
+ start: jest.fn(),
323
+ setOriginalUri: jest.fn(),
324
+ },
325
+ authState: mockedAuthState,
326
+ };
327
+ };
328
+ // This ensures its being mocked in jest.
329
+ jest.mock("@okta/okta-react", () => {
330
+ return {
331
+ useOktaAuth: () => mockedOktaAuth(),
332
+ };
333
+ });
334
+ };
335
+ jest.mock("highcharts/modules/boost", () => jest.fn());
336
+
337
+ /**
338
+ * Mocks the react-virtualized-auto-sizer component for testing environments.
339
+ *
340
+ * This function creates a mock implementation of the AutoSizer component from
341
+ * react-virtualized-auto-sizer, which is commonly used to measure and adapt to
342
+ * container dimensions. Instead of actual dimension measurements, the mock provides
343
+ * fixed dimensions (600x600), allowing tests to run consistently without actual DOM measuring.
344
+ *
345
+ * This is especially useful for testing components that use virtualized lists or grids,
346
+ * as it eliminates the need for setting up complex DOM environments just to get measurements.
347
+ *
348
+ * @example
349
+ * // In your jest setup file
350
+ * import { setupReactVirtualizedAutoSizer } from '@trackunit/react-test-setup';
351
+ *
352
+ * setupReactVirtualizedAutoSizer();
353
+ */
354
+ const setupReactVirtualizedAutoSizer = () => {
355
+ jest.mock("react-virtualized-auto-sizer", () => ({ children }) => children({ height: 600, width: 600, scaledWidth: 600, scaledHeight: 600 }));
356
+ };
357
+
358
+ /**
359
+ * Mock the ResizeObserver to be able to test components that use a resize observer
360
+ * Like useGeometry, useContainerBreakpoints, etc.
361
+ * Also componets that _use_ useGeometry, like <BaseInput/> and many more
362
+ *
363
+ * Recommended for all react libs
364
+ */
365
+ const setupResizeObserver = () => {
366
+ global.ResizeObserver = jest.fn().mockImplementation((callback) => ({
367
+ observe: jest.fn(),
368
+ unobserve: jest.fn(),
369
+ disconnect: jest.fn(),
370
+ }));
371
+ };
372
+
373
+ /**
374
+ * Mocks the @tanstack/react-virtual library for testing environments.
375
+ *
376
+ * This function creates a mock implementation of the useVirtualizer hook from
377
+ * the @tanstack/react-virtual library, which is used for efficiently rendering
378
+ * large lists and grids. The mock returns a simplified version that generates
379
+ * virtual items with deterministic sizes and provides all expected methods.
380
+ *
381
+ * Each virtual item has:
382
+ * - A consistent height (40px)
383
+ * - Index and key properties matching the item's position
384
+ * - Empty implementation of the measureRef function
385
+ *
386
+ * This allows for testing components that use virtualized lists without requiring
387
+ * actual DOM measurements or complex setup.
388
+ *
389
+ * @example
390
+ * // In your jest setup file
391
+ * import { setupTanstackReactVirtual } from '@trackunit/react-test-setup';
392
+ *
393
+ * setupTanstackReactVirtual();
394
+ */
395
+ const setupTanstackReactVirtual = () => {
396
+ jest.mock("@tanstack/react-virtual", () => ({
397
+ useVirtualizer: ({ count }) => ({
398
+ getVirtualItems: () => {
399
+ const result = [];
400
+ for (let i = 0; i < count; i++) {
401
+ result.push({ index: i, start: i * 40, key: i, measureRef: () => { } });
402
+ }
403
+ return result;
404
+ },
405
+ getTotalSize: () => count,
406
+ scrollToIndex: () => { },
407
+ scrollToOffset: () => { },
408
+ scrollToAlign: () => { },
409
+ scrollToItem: () => { },
410
+ resetAfterIndex: () => { },
411
+ resetAfterItem: () => { },
412
+ scrollTo: () => { },
413
+ measure: () => { },
414
+ }),
415
+ }));
416
+ };
417
+
418
+ /* eslint-disable @typescript-eslint/no-explicit-any */
419
+ /**
420
+ * Mocks the Temporal API to use a fixed time zone for testing.
421
+ *
422
+ * This function specifically mocks the Temporal.Now.timeZoneId method from the
423
+ * Temporal library to always return "Europe/Copenhagen", ensuring consistent
424
+ * time zone-dependent behavior in tests regardless of where they run.
425
+ *
426
+ * @example
427
+ * // In your jest setup file
428
+ * import { setupTimeZone } from '@trackunit/react-test-setup';
429
+ *
430
+ * setupTimeZone();
431
+ */
432
+ const setupTimeZone = () => {
433
+ jest.spyOn(polyfill.Temporal.Now, "timeZoneId").mockImplementation(() => "Europe/Copenhagen");
434
+ };
435
+ /**
436
+ * Sets up time, animation, and language-related mocks for testing environments.
437
+ *
438
+ * This function configures multiple aspects of the testing environment:
439
+ * 1. Sets a fixed time zone using setupTimeZone()
440
+ * 2. Disables React Spring animations for faster, deterministic tests
441
+ * 3. Mocks the useDebounce hook to immediately return values without delays
442
+ * 4. Overrides setTimeout and setInterval to execute immediately (0ms delay)
443
+ *
444
+ * These changes make tests faster and more predictable by eliminating real-time
445
+ * delays, animations, and time zone dependencies that could cause flaky tests.
446
+ *
447
+ * @example
448
+ * // In your jest setup file
449
+ * import { setupTimeAndLanguage } from '@trackunit/react-test-setup';
450
+ *
451
+ * setupTimeAndLanguage();
452
+ */
453
+ const setupTimeAndLanguage = () => {
454
+ setupTimeZone();
455
+ web.Globals.assign({
456
+ skipAnimation: true,
457
+ });
458
+ jest.mock("@trackunit/react-components", () => ({
459
+ ...jest.requireActual("@trackunit/react-components"),
460
+ useDebounce: (value) => value,
461
+ }));
462
+ const globalSetTimeout = global.setTimeout;
463
+ global.ORG_setTimeout = globalSetTimeout;
464
+ const globalSetInterval = global.setInterval;
465
+ global.ORG_setInterval = globalSetInterval;
466
+ global.setTimeout = function testSetTimeout(callback, ms, ...args) {
467
+ return globalSetTimeout.apply(this, [callback, 0]);
468
+ };
469
+ global.setInterval = function testSetInterval(callback, ms, ...args) {
470
+ return globalSetInterval.apply(this, [callback, 0]);
471
+ };
472
+ };
473
+
474
+ /**
475
+ * Sets up internationalization and translation mocks for testing environments.
476
+ *
477
+ * This function delegates to the implementation in setupTranslationsImpl.tsx to configure
478
+ * mock translations for react-i18next and @trackunit/i18n-library-translation. It creates
479
+ * simple mock implementations that return the key string as the translation, which allows
480
+ * for testing internationalized components without the complexity of actual translations.
481
+ *
482
+ * The mocks support common translation components and hooks like Trans, useTranslation,
483
+ * NamespaceTrans, and useNamespaceTranslation.
484
+ *
485
+ * @example
486
+ * // In your jest setup file
487
+ * import { setupTranslations } from '@trackunit/react-test-setup';
488
+ *
489
+ * setupTranslations();
490
+ */
491
+ const setupTranslations = () => {
492
+ // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
493
+ require("./setupTranslationsImpl").setupTranslations();
494
+ };
495
+
496
+ /**
497
+ * Sets up Web Streams API polyfills for testing environments.
498
+ *
499
+ * This function delegates to the implementation in setupWebStreamsImpl.ts to configure
500
+ * Web Streams API polyfills from web-streams-polyfill. These polyfills provide implementations
501
+ * of modern streaming APIs that may not be available in the Jest/JSDOM testing environment.
502
+ *
503
+ * The setup enables testing of components and utilities that rely on the Web Streams API,
504
+ * such as those that process streaming data or implement custom stream transformations.
505
+ *
506
+ * @example
507
+ * // In your jest setup file
508
+ * import { setupWebStreams } from '@trackunit/react-test-setup';
509
+ *
510
+ * setupWebStreams();
511
+ */
512
+ const setupWebStreams = () => {
513
+ // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
514
+ require("./setupWebStreamsImpl").setupWebStreams();
515
+ };
516
+
517
+ /**
518
+ * Sets up all available testing mocks in a single function call.
519
+ *
520
+ * This convenience function sets up all the test mocks provided by the library:
521
+ * - Canvas API mocks
522
+ * - Console error reporting to fail tests
523
+ * - Google Maps API and components mocks
524
+ * - React Helmet mocks
525
+ * - IntersectionObserver mocks
526
+ * - MatchMedia API mocks
527
+ * - React Testing Library and Okta authentication mocks
528
+ * - React Virtualized AutoSizer mocks
529
+ * - ResizeObserver mocks
530
+ * - Tanstack React Virtual mocks
531
+ * - Time and language related mocks (timezone, timers, etc.)
532
+ * - Translation mocks (i18n)
533
+ * - Web Streams API mocks
534
+ *
535
+ * Using this function is equivalent to calling each setup function individually.
536
+ *
537
+ * @param options Configuration options for individual mocks
538
+ * @param options.failOnConsoleOptions Options for setupFailOnConsole
539
+ * @example
540
+ * // In your jest setup file
541
+ * import { setupAllMocks } from '@trackunit/react-test-setup';
542
+ *
543
+ * setupAllMocks();
544
+ *
545
+ * // Or with options for specific mocks:
546
+ * setupAllMocks({
547
+ * failOnConsoleOptions: { shouldFailOnWarn: true }
548
+ * });
549
+ */
550
+ const setupAllMocks = (options = {}) => {
551
+ setupCanvasMock();
552
+ setupFailOnConsole(options.failOnConsoleOptions);
553
+ setupGoogleMaps();
554
+ setupHelmetMock();
555
+ setupIntersectionObserver();
556
+ setupMatchMediaMock();
557
+ setupReactTestingLibrary();
558
+ setupReactVirtualizedAutoSizer();
559
+ setupResizeObserver();
560
+ setupTanstackReactVirtual();
561
+ setupTimeAndLanguage();
562
+ setupTranslations();
563
+ setupWebStreams();
564
+ };
565
+
566
+ /**
567
+ * Sets up essential testing mocks that don't have external library dependencies.
568
+ *
569
+ * This convenience function configures a minimal set of test mocks that are broadly
570
+ * applicable for most React testing scenarios without requiring specific external
571
+ * libraries. It includes:
572
+ *
573
+ * - Canvas API mocks
574
+ * - Console error reporting to fail tests
575
+ * - IntersectionObserver mocks
576
+ * - MatchMedia API mocks
577
+ * - ResizeObserver mocks
578
+ * - Timer mocks (setTimeout, setInterval)
579
+ * - Web Streams API mocks
580
+ *
581
+ * This is perfect for projects that want essential testing mocks without bringing
582
+ * in dependencies for libraries they don't use like Google Maps, React Virtual, etc.
583
+ *
584
+ * @param options Configuration options for individual mocks
585
+ * @param options.failOnConsoleOptions Options for setupFailOnConsole
586
+ * @example
587
+ * // In your jest setup file
588
+ * import { setupBasicMocks } from '@trackunit/react-test-setup';
589
+ *
590
+ * setupBasicMocks();
591
+ *
592
+ * // Or with options for specific mocks:
593
+ * setupBasicMocks({
594
+ * failOnConsoleOptions: { shouldFailOnWarn: true }
595
+ * });
596
+ */
597
+ /**
598
+ * Sets up essential testing mocks with no external library dependencies.
599
+ *
600
+ * @param options Configuration options for the mocks
601
+ */
602
+ const setupBasicMocks = (options = {}) => {
603
+ // Core DOM and browser APIs
604
+ setupCanvasMock();
605
+ setupIntersectionObserver();
606
+ setupMatchMediaMock();
607
+ setupResizeObserver();
608
+ setupWebStreams();
609
+ // Time and error handling
610
+ setupTimeAndLanguage();
611
+ setupFailOnConsole(options.failOnConsoleOptions);
612
+ };
613
+
614
+ /**
615
+ * Sets up default testing mocks that cover most common React testing needs.
616
+ *
617
+ * This convenience function provides a balanced set of mocks that cover most React
618
+ * application testing needs. It includes all the basic mocks plus essential React
619
+ * testing utilities. Specifically, it includes:
620
+ *
621
+ * From setupBasicMocks:
622
+ * - Canvas API mocks
623
+ * - Console error reporting to fail tests
624
+ * - IntersectionObserver mocks
625
+ * - MatchMedia API mocks
626
+ * - ResizeObserver mocks
627
+ * - Timer mocks (setTimeout, setInterval)
628
+ * - Web Streams API mocks
629
+ *
630
+ * Plus these additional mocks:
631
+ * - React Testing Library and Okta authentication mocks
632
+ * - Translation mocks (i18n)
633
+ *
634
+ * This is ideal for most React applications that use i18n translations and need
635
+ * standard testing environment setup, without requiring specialized mocks for things
636
+ * like Google Maps or virtualized lists.
637
+ *
638
+ * @param options Configuration options for individual mocks
639
+ * @param options.failOnConsoleOptions Options for setupFailOnConsole
640
+ * @example
641
+ * // In your jest setup file
642
+ * import { setupDefaultMocks } from '@trackunit/react-test-setup';
643
+ *
644
+ * setupDefaultMocks();
645
+ *
646
+ * // Or with options for specific mocks:
647
+ * setupDefaultMocks({
648
+ * failOnConsoleOptions: { shouldFailOnWarn: true }
649
+ * });
650
+ */
651
+ /**
652
+ * Sets up default testing mocks covering most common React testing scenarios.
653
+ *
654
+ * @param options Configuration options for the mocks
655
+ */
656
+ const setupDefaultMocks = (options = {}) => {
657
+ // Set up all basic mocks first
658
+ setupBasicMocks(options);
659
+ // Add standard React testing utilities
660
+ setupReactTestingLibrary();
661
+ setupTranslations();
662
+ };
663
+
664
+ exports.setupAllMocks = setupAllMocks;
665
+ exports.setupBasicMocks = setupBasicMocks;
666
+ exports.setupCanvasMock = setupCanvasMock;
667
+ exports.setupDefaultMocks = setupDefaultMocks;
668
+ exports.setupFailOnConsole = setupFailOnConsole;
669
+ exports.setupGoogleMaps = setupGoogleMaps;
670
+ exports.setupHelmetMock = setupHelmetMock;
671
+ exports.setupIntersectionObserver = setupIntersectionObserver;
672
+ exports.setupMatchMediaMock = setupMatchMediaMock;
673
+ exports.setupReactTestingLibrary = setupReactTestingLibrary;
674
+ exports.setupReactVirtualizedAutoSizer = setupReactVirtualizedAutoSizer;
675
+ exports.setupResizeObserver = setupResizeObserver;
676
+ exports.setupTanstackReactVirtual = setupTanstackReactVirtual;
677
+ exports.setupTimeAndLanguage = setupTimeAndLanguage;
678
+ exports.setupTimeZone = setupTimeZone;
679
+ exports.setupTranslations = setupTranslations;
680
+ exports.setupWebStreams = setupWebStreams;
package/index.esm.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/index";