mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
test: ployfill: get rid of mock-require
This commit is contained in:
parent
8234201a39
commit
12751646fe
2 changed files with 19 additions and 20 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue