From 12751646fe51eeed9973397e6ee538bab7427be2 Mon Sep 17 00:00:00 2001 From: coderiaser Date: Tue, 13 Jan 2026 13:47:04 +0200 Subject: [PATCH] test: ployfill: get rid of mock-require --- client/modules/polyfill.js | 20 +++++++++++++++----- client/modules/polyfill.spec.js | 19 ++++--------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/client/modules/polyfill.js b/client/modules/polyfill.js index f5e7dc7a..ff0e59c5 100644 --- a/client/modules/polyfill.js +++ b/client/modules/polyfill.js @@ -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; diff --git a/client/modules/polyfill.spec.js b/client/modules/polyfill.spec.js index 67149e46..79d9dfda 100644 --- a/client/modules/polyfill.spec.js +++ b/client/modules/polyfill.spec.js @@ -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(); });