PromucFlow_constructor/app/client/test/setup.ts
Favour Ohanekwu 1379180ecd
feat: Split evaluation and linting (#17287)
* Evaluations and Linting now runs on separate web-workers for a much faster and responsive coding experience on Appsmith.
* Removed worker-loader webpack plugin.
2022-11-03 14:53:15 +05:30

62 lines
1.5 KiB
TypeScript

import { setupServer } from "msw/node";
import { handlers } from "./__mocks__/apiHandlers";
export const server = setupServer(...handlers);
window.scrollTo = jest.fn();
Element.prototype.scrollIntoView = jest.fn();
Element.prototype.scrollBy = jest.fn();
const mockObserveFn = () => {
return {
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
};
};
window.IntersectionObserver = jest.fn().mockImplementation(mockObserveFn);
window.ResizeObserver = jest.fn().mockImplementation(mockObserveFn);
// establish API mocking before all tests
beforeAll(() => server.listen());
// reset any request handlers that are declared as a part of our tests
// (i.e. for testing one-time error scenarios)
afterEach(() => server.resetHandlers());
// clean up once the tests are done
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 = () => {};
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;