mirror of
https://github.com/youzan/vant.git
synced 2025-10-19 18:14:13 +00:00
[bugfix] Tabs: incorrect line position in some cases (#3961)
This commit is contained in:
48
test/utils/dom.ts
Normal file
48
test/utils/dom.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { trigger } from './event';
|
||||
|
||||
function mockHTMLElementOffset() {
|
||||
Object.defineProperties(HTMLElement.prototype, {
|
||||
offsetParent: {
|
||||
get() {
|
||||
return this.parentNode || {};
|
||||
}
|
||||
},
|
||||
offsetLeft: {
|
||||
get() {
|
||||
return parseFloat(window.getComputedStyle(this).marginLeft) || 0;
|
||||
}
|
||||
},
|
||||
offsetTop: {
|
||||
get() {
|
||||
return parseFloat(window.getComputedStyle(this).marginTop) || 0;
|
||||
}
|
||||
},
|
||||
offsetHeight: {
|
||||
get() {
|
||||
return parseFloat(window.getComputedStyle(this).height) || 0;
|
||||
}
|
||||
},
|
||||
offsetWidth: {
|
||||
get() {
|
||||
return parseFloat(window.getComputedStyle(this).width) || 0;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
mockHTMLElementOffset();
|
||||
|
||||
export function mockGetBoundingClientRect(rect: ClientRect | DOMRect): Function {
|
||||
const originMethod = Element.prototype.getBoundingClientRect;
|
||||
|
||||
Element.prototype.getBoundingClientRect = <any>jest.fn(() => rect);
|
||||
|
||||
return function () {
|
||||
Element.prototype.getBoundingClientRect = originMethod;
|
||||
};
|
||||
}
|
||||
|
||||
export function mockScrollTop(value: number) {
|
||||
Object.defineProperty(window, 'scrollTop', { value, writable: true });
|
||||
trigger(window, 'scroll');
|
||||
}
|
Reference in New Issue
Block a user