2021-04-02 09:47:16 +00:00
|
|
|
import { setupServer } from "msw/node";
|
|
|
|
|
import { handlers } from "./__mocks__/apiHandlers";
|
2023-02-08 11:23:39 +00:00
|
|
|
import "../src/polyfills/requestIdleCallback";
|
2023-08-07 09:31:45 +00:00
|
|
|
import { Crypto } from "@peculiar/webcrypto";
|
|
|
|
|
|
|
|
|
|
global.crypto = new Crypto();
|
2023-02-08 11:23:39 +00:00
|
|
|
|
2021-04-02 09:47:16 +00:00
|
|
|
export const server = setupServer(...handlers);
|
|
|
|
|
|
2023-03-15 05:39:46 +00:00
|
|
|
jest.mock("api/Api", () => ({
|
|
|
|
|
__esModule: true,
|
|
|
|
|
default: class Api {},
|
|
|
|
|
}));
|
|
|
|
|
|
2021-05-20 12:03:08 +00:00
|
|
|
window.scrollTo = jest.fn();
|
2021-08-12 05:45:38 +00:00
|
|
|
Element.prototype.scrollIntoView = jest.fn();
|
|
|
|
|
Element.prototype.scrollBy = jest.fn();
|
2022-01-25 15:28:31 +00:00
|
|
|
|
2023-03-23 11:41:58 +00:00
|
|
|
jest.mock("../src/api/Api.ts", () => ({
|
|
|
|
|
__esModule: true,
|
|
|
|
|
default: class Api {},
|
|
|
|
|
}));
|
|
|
|
|
|
2023-02-08 11:23:39 +00:00
|
|
|
beforeAll(() => {
|
|
|
|
|
window.IntersectionObserver = jest
|
|
|
|
|
.fn()
|
|
|
|
|
.mockImplementation((fn: (entry: any) => any) => {
|
|
|
|
|
return {
|
|
|
|
|
observe: () => {
|
|
|
|
|
fn([
|
|
|
|
|
{
|
|
|
|
|
isIntersecting: true,
|
|
|
|
|
boundingClientRect: {
|
|
|
|
|
top: 64,
|
|
|
|
|
left: 293,
|
|
|
|
|
},
|
|
|
|
|
intersectionRect: {
|
|
|
|
|
width: 1296,
|
|
|
|
|
height: 424,
|
|
|
|
|
top: 64,
|
|
|
|
|
left: 293,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
},
|
|
|
|
|
unobserve: jest.fn(),
|
|
|
|
|
disconnect: jest.fn(),
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
window.ResizeObserver = jest.fn().mockImplementation(() => {
|
|
|
|
|
return {
|
|
|
|
|
observe: jest.fn(),
|
|
|
|
|
unobserve: jest.fn(),
|
|
|
|
|
disconnect: jest.fn(),
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
});
|
2021-05-20 12:03:08 +00:00
|
|
|
|
2021-04-02 09:47:16 +00:00
|
|
|
// establish API mocking before all tests
|
2021-05-18 18:29:39 +00:00
|
|
|
beforeAll(() => server.listen());
|
2021-04-02 09:47:16 +00:00
|
|
|
// reset any request handlers that are declared as a part of our tests
|
|
|
|
|
// (i.e. for testing one-time error scenarios)
|
2021-05-18 18:29:39 +00:00
|
|
|
afterEach(() => server.resetHandlers());
|
2021-04-02 09:47:16 +00:00
|
|
|
// clean up once the tests are done
|
2021-05-18 18:29:39 +00:00
|
|
|
afterAll(() => server.close());
|
|
|
|
|
|
|
|
|
|
// popper.js fix for jest tests
|
|
|
|
|
document.createRange = () => {
|
|
|
|
|
const range = new Range();
|
|
|
|
|
|
|
|
|
|
range.getBoundingClientRect = jest.fn();
|
|
|
|
|
|
|
|
|
|
range.getClientRects = () => {
|
|
|
|
|
return {
|
|
|
|
|
item: () => null,
|
|
|
|
|
length: 0,
|
|
|
|
|
[Symbol.iterator]: jest.fn(),
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return range;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// jest events doesnt seem to be handling scrollTo
|
|
|
|
|
Element.prototype.scrollTo = () => {};
|
2022-11-03 09:23:15 +00:00
|
|
|
|
|
|
|
|
class WorkerStub {
|
|
|
|
|
url: string;
|
|
|
|
|
onmessage: CallableFunction;
|
|
|
|
|
constructor(stringUrl: string) {
|
|
|
|
|
this.url = stringUrl;
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
|
|
|
this.onmessage = () => {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
postMessage(msg) {
|
|
|
|
|
this.onmessage(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.Worker = WorkerStub as any;
|