-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.fs.test.ts
41 lines (28 loc) · 939 Bytes
/
module.fs.test.ts
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
39
40
41
import dependency from 'fs';
jest.mock('fs');
const fs = jest.mocked(dependency);
describe('fs.readFileSync', () => {
it('should call the mock implementation', () => {
expect.assertions(1);
fs.readFileSync('a b c');
fs.readFileSync('a b c');
fs.readFileSync('a b c');
expect(fs.readFileSync).toHaveBeenCalledTimes(3);
});
it('should call the mocked module method', () => {
expect.assertions(1);
fs.readFileSync('path', 'utf8');
expect(fs.readFileSync).toHaveBeenCalledWith('path', 'utf8');
});
it('should provide empty file contents', () => {
expect.assertions(1);
const result = fs.readFileSync('path', 'utf8');
expect(result).toBe('');
});
it('should provide the mocked file contents', () => {
expect.assertions(1);
fs.readFileSync.mockReturnValueOnce('a b c');
const result = fs.readFileSync('path', 'utf8');
expect(result).toBe('a b c');
});
});