You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/test/runtime/samples/window-bind-scroll-update/_config.js

43 lines
796 B

import { vi } from 'vitest';
let original_scrollTo;
export default {
before_test() {
vi.useFakeTimers();
Object.defineProperties(window, {
pageYOffset: {
value: 0,
configurable: true,
writable: true
},
pageXOffset: {
value: 0,
configurable: true,
writable: true
}
});
original_scrollTo = window.scrollTo;
window.scrollTo = (x, y) => {
window.pageXOffset = x;
window.pageYOffset = y;
};
},
after_test() {
vi.useRealTimers();
window.scrollTo = original_scrollTo;
},
async test({ assert, component, window }) {
assert.equal(window.pageYOffset, 0);
// clear the previous 'scrolling' state
await vi.runAllTimersAsync();
component.scrollY = 100;
await vi.runAllTimersAsync();
assert.equal(window.pageYOffset, 100);
}
};