-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathindex.test.ts
More file actions
35 lines (30 loc) · 894 Bytes
/
index.test.ts
File metadata and controls
35 lines (30 loc) · 894 Bytes
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
import { mockOne, mockTwo, mockThree, unmockedFunction } from './index';
jest.mock('./index', () => {
const originalModule =
jest.requireActual<typeof import('./index')>('./index');
return {
...originalModule,
mockOne: jest.fn(),
mockTwo: jest.fn(),
mockThree: jest.fn(),
};
});
describe('partial mocking', () => {
afterAll(() => {
jest.unmock('./index');
});
test('mockOne, mockTwo, mockThree should not log into console', () => {
mockOne();
mockTwo();
mockThree();
expect(mockOne).toHaveBeenCalled();
expect(mockTwo).toHaveBeenCalled();
expect(mockThree).toHaveBeenCalled();
});
test('unmockedFunction should log into console', () => {
const consoleSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
unmockedFunction();
expect(consoleSpy).toHaveBeenCalled();
consoleSpy.mockRestore();
});
});