diff --git a/readme.md b/readme.md index b4e848d..91429e7 100644 --- a/readme.md +++ b/readme.md @@ -116,6 +116,19 @@ expect( ).wasCalledOnce(); ``` +### Verify Constructor Parameters + +```ts +const mockInstance = Mock.create().setup( + setupConstructor(), + ); + +new mockInstance.mockConstructor(serviceInstance); + +expect(mockInstance.withConstructor().withParameters(serviceInstance)).wasCalledOnce(); + +``` + ### Verify Getter: ```typescript const mockedService: IMocked = Mock.create().setup(setupProperty('propOne')); diff --git a/spec/examples/exampleTests.spec.ts b/spec/examples/exampleTests.spec.ts index 9a197e9..dbd71f1 100644 --- a/spec/examples/exampleTests.spec.ts +++ b/spec/examples/exampleTests.spec.ts @@ -6,6 +6,7 @@ import { setupFunction, setupProperty, setupStaticFunction, + setupConstructor, } from '../../main'; import { ClassWithConstructorArgument, ClassWithInstanceArgument } from './exampleImplementation'; import { IMyService, MyService } from './exampleImports'; @@ -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().setup( + setupConstructor(), + ); + const mockService = Mock.create(); + + new mockInstance.mockConstructor(mockService.mock); + + expect(mockInstance.withConstructor().withParameters(mockService.mock)).wasCalledOnce(); + }); +});