test: improve mock spy (#8483)

This commit is contained in:
neverland
2021-04-09 09:53:25 +08:00
committed by GitHub
parent 63ace39d2a
commit 1217088d95
4 changed files with 37 additions and 29 deletions

View File

@@ -38,13 +38,9 @@ export function mockScrollIntoView() {
}
export function mockGetBoundingClientRect(rect: Partial<DOMRect>): () => void {
const originMethod = Element.prototype.getBoundingClientRect;
Element.prototype.getBoundingClientRect = jest.fn(() => rect as DOMRect);
return function () {
Element.prototype.getBoundingClientRect = originMethod;
};
const spy = jest.spyOn(Element.prototype, 'getBoundingClientRect');
spy.mockReturnValue(rect as DOMRect);
return () => spy.mockRestore();
}
export async function mockScrollTop(value: number) {