test: ployfill: get rid of mock-require

This commit is contained in:
coderiaser 2026-01-13 13:47:04 +02:00
parent 8234201a39
commit 12751646fe
2 changed files with 19 additions and 20 deletions

View file

@ -1,10 +1,20 @@
'use strict';
/* global DOM */
require('domtokenlist-shim');
const scrollIntoViewIfNeeded = require('scroll-into-view-if-needed');
const _scrollIntoViewIfNeeded = require('scroll-into-view-if-needed');
DOM.scrollIntoViewIfNeeded = (el) => scrollIntoViewIfNeeded(el, {
block: 'nearest',
});
globalThis.DOM = globalThis.DOM || {};
const scrollIntoViewIfNeeded = (el, overrides = {}) => {
const {
scroll = _scrollIntoViewIfNeeded,
} = overrides;
return scroll(el, {
block: 'nearest',
});
};
globalThis.DOM.scrollIntoViewIfNeeded = scrollIntoViewIfNeeded;
module.exports.scrollIntoViewIfNeeded = scrollIntoViewIfNeeded;

View file

@ -1,24 +1,15 @@
'use strict';
const {test, stub} = require('supertape');
const mockRequire = require('mock-require');
const {stopAll} = mockRequire;
const {scrollIntoViewIfNeeded} = require('./polyfill');
test('cloudcmd: client: polyfill: scrollIntoViewIfNeaded', (t) => {
const {DOM} = global;
const scroll = stub();
const el = {};
global.DOM = {};
mockRequire('scroll-into-view-if-needed', scroll);
mockRequire.reRequire('./polyfill');
global.DOM.scrollIntoViewIfNeeded(el);
mockRequire.stop('scroll-into-view-if-neaded');
global.DOM = DOM;
scrollIntoViewIfNeeded(el, {
scroll,
});
const args = [
el, {
@ -26,8 +17,6 @@ test('cloudcmd: client: polyfill: scrollIntoViewIfNeaded', (t) => {
},
];
stopAll();
t.calledWith(scroll, args, 'should call scrollIntoViewIfNeaded');
t.end();
});