Skip to content

Commit 89119e4

Browse files
kunhanlecpojer
authored andcommitted
Make the getMockImplementation() in Mocker module as a public method. (jestjs#1244)
1 parent 4462ef8 commit 89119e4

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

packages/jest-haste-map/src/__tests__/index-test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,7 @@ describe('HasteMap', () => {
445445

446446
it('ignores files that do not exist', () => {
447447
const watchman = require('../crawlers/watchman');
448-
// getMockImplementation should be a public method.
449-
const mockImpl = watchman._getMockImplementation();
448+
const mockImpl = watchman.getMockImplementation();
450449
// Wrap the watchman mock and add an invalid file to the file list.
451450
watchman.mockImplementation((roots, extensions, ignore, data) => {
452451
return mockImpl(roots, extensions, ignore, data).then(() => {

packages/jest-mock/src/__tests__/jest-mock-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,19 @@ describe('moduleMocker', () => {
124124
});
125125
});
126126

127+
describe('getMockImplementation', () => {
128+
it('should mock calls to a mock function', () => {
129+
const mockFn = moduleMocker.getMockFunction();
130+
131+
mockFn.mockImplementation(() => {
132+
return 'Foo';
133+
});
134+
135+
expect(typeof mockFn.getMockImplementation()).toBe('function');
136+
expect(mockFn.getMockImplementation()()).toBe('Foo');
137+
});
138+
});
139+
127140
describe('mockImplementationOnce', () => {
128141
it('should mock single call to a mock function', () => {
129142
const mockFn = moduleMocker.getMockFunction();

packages/jest-mock/src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ function makeComponent(metadata: MockFunctionMetadata): Mock {
271271

272272
f = createMockFunction(metadata, mockConstructor);
273273
f._isMockFunction = true;
274-
f._getMockImplementation = () => mockImpl;
274+
f.getMockImplementation = () => mockImpl;
275275
f.mock = {calls, instances};
276276

277277
f.mockClear = () => {
@@ -389,7 +389,7 @@ function getMetadata(
389389
} else if (type === 'function') {
390390
metadata.name = component.name;
391391
if (component._isMockFunction) {
392-
metadata.mockImpl = component._getMockImplementation();
392+
metadata.mockImpl = component.getMockImplementation();
393393
}
394394
}
395395

0 commit comments

Comments
 (0)