Skip to content

Commit

Permalink
add examples / docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Roaders committed Oct 18, 2023
1 parent 23456c9 commit 0765a1b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ expect(
).wasCalledOnce();
```

### Verify Constructor Parameters

```ts
const mockInstance = Mock.create<ClassWithInstanceArgument, typeof ClassWithInstanceArgument>().setup(
setupConstructor(),
);

new mockInstance.mockConstructor(serviceInstance);

expect(mockInstance.withConstructor().withParameters(serviceInstance)).wasCalledOnce();

```

### Verify Getter:
```typescript
const mockedService: IMocked<IMyService> = Mock.create<IMyService>().setup(setupProperty('propOne'));
Expand Down
14 changes: 14 additions & 0 deletions spec/examples/exampleTests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
setupFunction,
setupProperty,
setupStaticFunction,
setupConstructor,
} from '../../main';
import { ClassWithConstructorArgument, ClassWithInstanceArgument } from './exampleImplementation';
import { IMyService, MyService } from './exampleImports';
Expand Down Expand Up @@ -118,3 +119,16 @@ describe('verify function calls', () => {
expect(functionVerifier.withParameters('someValue')).wasCalledOnce();
});
});

describe('verify constructor calls', () => {
it(`should verify that constructor was called`, () => {
const mockInstance = Mock.create<ClassWithInstanceArgument, typeof ClassWithInstanceArgument>().setup(
setupConstructor(),
);
const mockService = Mock.create<IMyService>();

new mockInstance.mockConstructor(mockService.mock);

expect(mockInstance.withConstructor().withParameters(mockService.mock)).wasCalledOnce();
});
});

0 comments on commit 0765a1b

Please sign in to comment.