Skip to content

Commit c9b3491

Browse files
committed
Document fallbackMockImplementation works for mock
1 parent 12358fd commit c9b3491

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,19 @@ describe('Party Tests', () => {
5050

5151
expect(mock.getPartyType()).toBe('west coast party');
5252
});
53-
});
53+
54+
test('throwing an error if we forget to specify the return value')
55+
const mock = mock<PartyProvider>(
56+
{},
57+
{
58+
fallbackMockImplementation: () => {
59+
throw new Error('not mocked');
60+
},
61+
}
62+
);
63+
64+
expect(() => mock.getPartyType()).toThrowError('not mocked');
65+
});
5466
```
5567

5668
## Assigning Mocks with a Type

src/Mock.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,19 @@ describe('jest-mock-extended', () => {
124124
expect(mockObj.getSomethingWithArgs(1, 2)).toBe(1);
125125
});
126126

127+
test('Can specify fallbackMockImplementation', () => {
128+
const mockObj = mock<MockInt>(
129+
{},
130+
{
131+
fallbackMockImplementation: () => {
132+
throw new Error('not mocked');
133+
},
134+
}
135+
);
136+
137+
expect(() => mockObj.getSomethingWithArgs(1, 2)).toThrowError('not mocked');
138+
});
139+
127140
test('Can specify multiple calledWith', () => {
128141
const mockObj = mock<MockInt>();
129142
mockObj.getSomethingWithArgs.calledWith(1, 2).mockReturnValue(3);

0 commit comments

Comments
 (0)