2022-04-04 08:51:32 -07:00
|
|
|
'use strict';
|
|
|
|
|
2022-11-15 05:43:26 -08:00
|
|
|
import { __clear as clearApiMocks } from '../api/__mocks__';
|
2022-04-04 08:51:32 -07:00
|
|
|
|
|
|
|
// API mocking
|
|
|
|
jest.mock('soapbox/api');
|
|
|
|
afterEach(() => clearApiMocks());
|
|
|
|
|
2022-10-28 10:01:39 -07:00
|
|
|
// Query mocking
|
|
|
|
jest.mock('soapbox/queries/client');
|
|
|
|
|
2022-04-21 15:03:29 -07:00
|
|
|
// Mock IndexedDB
|
|
|
|
// https://dev.to/andyhaskell/testing-your-indexeddb-code-with-jest-2o17
|
|
|
|
require('fake-indexeddb/auto');
|
|
|
|
|
2022-04-04 08:51:32 -07:00
|
|
|
// Mock external dependencies
|
2022-04-21 10:24:54 -07:00
|
|
|
jest.mock('uuid', () => ({ v4: jest.fn(() => '1') }));
|
2022-04-06 07:10:21 -07:00
|
|
|
|
|
|
|
const intersectionObserverMock = () => ({ observe: () => null, disconnect: () => null });
|
|
|
|
window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock);
|
2022-05-31 08:20:32 -07:00
|
|
|
|
|
|
|
Object.defineProperty(window, 'matchMedia', {
|
|
|
|
writable: true,
|
|
|
|
value: jest.fn().mockImplementation(query => ({
|
|
|
|
matches: false,
|
|
|
|
media: query,
|
|
|
|
onchange: null,
|
|
|
|
addListener: jest.fn(), // Deprecated
|
|
|
|
removeListener: jest.fn(), // Deprecated
|
|
|
|
addEventListener: jest.fn(),
|
|
|
|
removeEventListener: jest.fn(),
|
|
|
|
dispatchEvent: jest.fn(),
|
|
|
|
})),
|
|
|
|
});
|