1.7 KB50 lines
Blame
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8// jest-dom adds custom jest matchers for asserting on DOM nodes.
9// allows you to do things like:
10// expect(element).toHaveTextContent(/react/i)
11// learn more: https://github.com/testing-library/jest-dom
12import '@testing-library/jest-dom';
13
14// Use __mocks__/logger so calls to logger don't output to console, but
15// console.log still works for debugging tests.
16jest.mock('./logger');
17
18// jest doesn't have the stylex compilation step, let's just mock it
19jest.mock('@stylexjs/stylex');
20
21// Mock MessageBus via LocalWebSocketEventBus before other logic which might have effects on it.
22jest.mock('./LocalWebSocketEventBus', () => {
23 // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/consistent-type-imports
24 const TestMessageBus = (require('./TestingMessageBus') as typeof import('./TestingMessageBus'))
25 .TestingEventBus;
26 return {LocalWebSocketEventBus: TestMessageBus};
27});
28
29import {configure} from '@testing-library/react';
30
31const IS_CI = !!process.env.SANDCASTLE || !!process.env.GITHUB_ACTIONS;
32configure({
33 // bump waitFor timeouts in CI where jobs may run slower
34 ...(IS_CI ? {asyncUtilTimeout: 5_000} : undefined),
35 ...(process.env.HIDE_RTL_DOM_ERRORS
36 ? {
37 getElementError: (message: string | null) => {
38 const error = new Error(message ?? '');
39 error.name = 'TestingLibraryElementError';
40 error.stack = undefined;
41 return error;
42 },
43 }
44 : {}),
45});
46
47global.ResizeObserver = require('resize-observer-polyfill');
48
49global.fetch = jest.fn().mockImplementation(() => Promise.resolve());
50