UNPKG

vanillajs-browser-helpers

Version:

Collection of convenience code snippets (helpers) that aims to make it a little easier to work with vanilla JS in the browser

24 lines (21 loc) 483 B
interface Overrides { top?: number, left?: number, right?: number, bottom?: number, } export function mockClientRect(overrides?: Overrides): () => void { const spy = jest.spyOn(HTMLElement.prototype, 'getBoundingClientRect') .mockReturnValue(Object.assign({ width: 100, height: 100, top: 0, left: 0, right: 0, bottom: 0, x: 0, y: 0, toJSON: () => undefined }, overrides)); return () => spy.mockRestore(); }