-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconcatFiles.spec.js
38 lines (38 loc) · 1.01 KB
/
concatFiles.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const concatFiles = require('@src/concatFiles');
const fs = require('fs');
describe('concatFiles', () => {
let buffer = '';
beforeEach(() => {
buffer = '';
fs.readFile = jest.fn().mockImplementation((filename, encoding, cb) => {
let result;
switch (filename) {
case 'file1.txt': result = 'foo';
break;
case 'file2.txt': result = 'bar';
break;
case 'file3.txt': result = 'world';
break;
}
cb(null, result);
});
fs.appendFile = jest.fn().mockImplementation((fd, content, cb) => {
buffer = buffer + content;
cb();
});
fs.open = jest.fn().mockImplementation((filename, mode, cb) => {
cb(null, 3);
});
});
it('should concat a list of files in order', (done) => {
concatFiles('file1.txt',
'file2.txt',
'file3.txt',
'combined.txt',
(err) => {
expect(err).toEqual(undefined);
expect(buffer).toEqual('foobarworld');
done();
});
});
});