mirror of
https://github.com/youzan/vant.git
synced 2025-10-22 11:54:02 +00:00
test: improve mock spy (#8483)
This commit is contained in:
10
test/dom.ts
10
test/dom.ts
@@ -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) {
|
||||
|
Reference in New Issue
Block a user