chore: improve test utils

This commit is contained in:
陈嘉涵
2020-02-20 16:31:42 +08:00
parent 9b70d1a4dc
commit 871398b223
3 changed files with 11 additions and 21 deletions
+7 -5
View File
@@ -30,13 +30,12 @@ function mockHTMLElementOffset() {
});
}
function mockScrollIntoView() {
Element.prototype.scrollIntoView = function() {};
export function mockScrollIntoView() {
const fn = jest.fn();
Element.prototype.scrollIntoView = fn;
return fn;
}
mockScrollIntoView();
mockHTMLElementOffset();
export function mockGetBoundingClientRect(
rect: ClientRect | DOMRect
): Function {
@@ -53,3 +52,6 @@ export function mockScrollTop(value: number) {
Object.defineProperty(window, 'scrollTop', { value, writable: true });
trigger(window, 'scroll');
}
mockScrollIntoView();
mockHTMLElementOffset();