Skip to content

Commit 8bf2d2d

Browse files
committed
refactor!: Remove mock options
BREAKING CHANGE: You can no longer pass a custom expectation repository or a custom expectation factory to the `mock()` function. These options weren't documented very well and just bloated the API.
1 parent 888a0b5 commit 8bf2d2d

3 files changed

Lines changed: 11 additions & 41 deletions

File tree

src/mock/mock.spec.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/mock/mock.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { isMatcher } from '../expectation/matcher';
2-
import { ExpectationRepository } from '../expectation/repository/expectation-repository';
32
import { StrongRepository } from '../expectation/repository/strong-repository';
43
import { StrongExpectation } from '../expectation/strong-expectation';
54
import {
@@ -30,18 +29,6 @@ export const setRecording = (recording: boolean) => {
3029
isRecording = recording;
3130
};
3231

33-
interface MockOptions {
34-
/**
35-
* You can provide your own repository to store and find expectations.
36-
*/
37-
repository?: ExpectationRepository;
38-
39-
/**
40-
* You can provide your own way of creating expectations.
41-
*/
42-
expectationFactory?: ExpectationFactory;
43-
}
44-
4532
/**
4633
* Create a type safe mock.
4734
*
@@ -54,14 +41,12 @@ interface MockOptions {
5441
*
5542
* fn() === 23;
5643
*/
57-
export const mock = <T>({
58-
repository = new StrongRepository(),
59-
expectationFactory = strongExpectationFactory,
60-
}: MockOptions = {}): Mock<T> => {
44+
export const mock = <T>(): Mock<T> => {
6145
const pendingExpectation = new RepoSideEffectPendingExpectation(
62-
expectationFactory
46+
strongExpectationFactory
6347
);
6448

49+
const repository = new StrongRepository();
6550
const stub = createStub<T>(repository, pendingExpectation, () => isRecording);
6651

6752
setMockState(stub, { repository, pendingExpectation });

src/verify/reset.spec.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
/* eslint-disable class-methods-use-this */
2-
import { StrongRepository } from '../expectation/repository/strong-repository';
2+
import { NotAMock } from '../errors';
33
import { when } from '../index';
4+
import { getMockState } from '../mock/map';
45
import { mock } from '../mock/mock';
56
import { reset } from './reset';
67

78
describe('reset', () => {
89
it('should clear the expectation repo', () => {
9-
const repo = new StrongRepository();
10-
const fn = mock<() => void>({ repository: repo });
10+
const fn = mock<() => void>();
1111

1212
when(() => fn()).thenReturn(undefined);
1313
reset(fn);
1414

15-
expect(repo.getUnmet()).toHaveLength(0);
15+
expect(getMockState(fn).repository.getUnmet()).toHaveLength(0);
16+
});
17+
18+
it('should throw if called on a non mock', () => {
19+
expect(() => reset('bla')).toThrow(NotAMock);
1620
});
1721
});

0 commit comments

Comments
 (0)