From 0765a1b6859d4948a2e71c261ea4832f9ffcbdbe Mon Sep 17 00:00:00 2001 From: Giles Roadnight <10414642+Roaders@users.noreply.github.com> Date: Wed, 18 Oct 2023 09:56:44 +0100 Subject: [PATCH] add examples / docs --- readme.md | 13 +++++++++++++ spec/examples/exampleTests.spec.ts | 14 ++++++++++++++ 2 files changed, 27 insertions(+) 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(); + }); +});