While checking other references, I did manage to get the mock test working. I changed the jest-mocks.spec.ts
to be:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | jest.mock('./jest-mock', () => { return { // Define Function Mock Return Values GetOne: jest.fn( () => 3 ) } }); const MockObject = require('./jest-mock'); describe('mock function', () => { it('should create mock', () => { expect(jest.isMockFunction(MockObject.GetOne)).toBeTruthy(); }); it('should return mock values', () => { expect(MockObject.GetOne()).toBe(3); expect(MockObject.GetOne).toHaveBeenCalled(); expect(MockObject.GetTwo).toBeUndefined(); }); }); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.