From e24f41535aa5698ac4fcb9b013ddbc6e11379e3b Mon Sep 17 00:00:00 2001 From: johanblumenberg Date: Sat, 13 Jan 2018 12:51:36 +0100 Subject: [PATCH] Throwing an Error when calling imock() without Proxy support --- src/ts-mockito.ts | 2 +- test/mocking.types.spec.ts | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/ts-mockito.ts b/src/ts-mockito.ts index a768397..1ffd686 100644 --- a/src/ts-mockito.ts +++ b/src/ts-mockito.ts @@ -40,7 +40,7 @@ export function imock(): T { const mockedValue = new Mocker(Empty, true).getMock(); if (typeof Proxy === "undefined") { - return mockedValue; + throw new Error("Mocking of interfaces requires support for Proxy objects"); } const tsmockitoMocker = mockedValue.__tsmockitoMocker; return new Proxy(mockedValue, tsmockitoMocker.createCatchAllHandlerForRemainingPropertiesWithoutGetters()); diff --git a/test/mocking.types.spec.ts b/test/mocking.types.spec.ts index 075ade2..54ed6ee 100644 --- a/test/mocking.types.spec.ts +++ b/test/mocking.types.spec.ts @@ -157,18 +157,29 @@ describe("mocking", () => { let mockedFoo: SampleInterface; let foo: SampleInterface; - it("can create interface mock", () => { - // given + if (typeof Proxy === "undefined") { + it("throws when creating interface mock", () => { + // given - // when - mockedFoo = imock(); - foo = instance(mockedFoo); + // when - // then - }); + // then + expect(() => imock()).toThrow(); + }); + } if (typeof Proxy !== "undefined") { + it("can create interface mock", () => { + // given + + // when + mockedFoo = imock(); + foo = instance(mockedFoo); + + // then + }); + it("can verify call count", () => { // given mockedFoo = imock();