Skip to content

Commit dc5867b

Browse files
committed
feature: client: key: vim: get rid of mock-require
1 parent 77b70b2 commit dc5867b

2 files changed

Lines changed: 18 additions & 18 deletions

File tree

client/key/vim/index.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,16 @@ const getOperations = (event, deps) => {
4040
toggleSelectedFile,
4141
Buffer = {},
4242
createFindNext = _createFindNext,
43+
createFindPrevious = _createFindPrevious,
4344
} = deps;
4445

4546
return {
4647
findNext: createFindNext({
4748
setCurrentByName,
4849
}),
50+
findPrevious: createFindPrevious({
51+
setCurrentByName,
52+
}),
4953
escape: unselectFiles,
5054

5155
remove: () => {
@@ -122,16 +126,18 @@ const getOperations = (event, deps) => {
122126

123127
setCurrentByName(result);
124128
},
125-
126-
findPrevious: () => {
127-
const name = finder.findPrevious();
128-
setCurrentByName(name);
129-
},
130129
};
131130
};
132131

133132
module.exports.selectFile = selectFileNotParent;
134133

134+
const _createFindPrevious = (overrides = {}) => () => {
135+
const {setCurrentByName} = overrides;
136+
const name = finder.findPrevious();
137+
138+
setCurrentByName(name);
139+
};
140+
135141
const _createFindNext = (overrides = {}) => () => {
136142
const {setCurrentByName} = overrides;
137143
const name = finder.findNext();

client/key/vim/index.spec.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const {join} = require('node:path');
44
const {test, stub} = require('supertape');
5-
const mockRequire = require('mock-require');
65

76
const dir = '../';
87

@@ -18,8 +17,8 @@ const vim = require('./index.js');
1817
const {assign} = Object;
1918
const {DOM} = globalThis;
2019
const {Buffer} = DOM;
21-
const pathFind = join(dir, 'vim', 'find');
22-
const {reRequire, stopAll} = mockRequire;
20+
21+
const {reRequire, stopAll} = require('mock-require');
2322

2423
test('cloudcmd: client: key: set next file: no', (t) => {
2524
const element = {};
@@ -584,19 +583,14 @@ test('cloudcmd: client: key: n', (t) => {
584583

585584
test('cloudcmd: client: key: N', (t) => {
586585
const findPrevious = stub();
587-
588-
mockRequire(pathFind, {
589-
findPrevious,
590-
});
591-
592-
const vim = reRequire(`${dir}vim`);
586+
const createFindPrevious = stub().returns(findPrevious);
593587
const event = {};
594588

595-
vim('N', event);
596-
597-
stopAll();
589+
vim('N', event, {
590+
createFindPrevious,
591+
});
598592

599-
t.calledWithNoArgs(findPrevious, 'should call findPrevious');
593+
t.calledWithNoArgs(findPrevious);
600594
t.end();
601595
});
602596

0 commit comments

Comments
 (0)