addons/isl/src/setupTests.tsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318// jest-dom adds custom jest matchers for asserting on DOM nodes.
b69ab319// allows you to do things like:
b69ab3110// expect(element).toHaveTextContent(/react/i)
b69ab3111// learn more: https://github.com/testing-library/jest-dom
b69ab3112import '@testing-library/jest-dom';
b69ab3113
b69ab3114// Use __mocks__/logger so calls to logger don't output to console, but
b69ab3115// console.log still works for debugging tests.
b69ab3116jest.mock('./logger');
b69ab3117
b69ab3118// jest doesn't have the stylex compilation step, let's just mock it
b69ab3119jest.mock('@stylexjs/stylex');
b69ab3120
b69ab3121// Mock MessageBus via LocalWebSocketEventBus before other logic which might have effects on it.
b69ab3122jest.mock('./LocalWebSocketEventBus', () => {
b69ab3123 // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/consistent-type-imports
b69ab3124 const TestMessageBus = (require('./TestingMessageBus') as typeof import('./TestingMessageBus'))
b69ab3125 .TestingEventBus;
b69ab3126 return {LocalWebSocketEventBus: TestMessageBus};
b69ab3127});
b69ab3128
b69ab3129import {configure} from '@testing-library/react';
b69ab3130
b69ab3131const IS_CI = !!process.env.SANDCASTLE || !!process.env.GITHUB_ACTIONS;
b69ab3132configure({
b69ab3133 // bump waitFor timeouts in CI where jobs may run slower
b69ab3134 ...(IS_CI ? {asyncUtilTimeout: 5_000} : undefined),
b69ab3135 ...(process.env.HIDE_RTL_DOM_ERRORS
b69ab3136 ? {
b69ab3137 getElementError: (message: string | null) => {
b69ab3138 const error = new Error(message ?? '');
b69ab3139 error.name = 'TestingLibraryElementError';
b69ab3140 error.stack = undefined;
b69ab3141 return error;
b69ab3142 },
b69ab3143 }
b69ab3144 : {}),
b69ab3145});
b69ab3146
b69ab3147global.ResizeObserver = require('resize-observer-polyfill');
b69ab3148
b69ab3149global.fetch = jest.fn().mockImplementation(() => Promise.resolve());