Skip to content

Commit

Permalink
Throwing an Error when calling imock() without Proxy support
Browse files Browse the repository at this point in the history
  • Loading branch information
johanblumenberg committed Jan 19, 2018
1 parent 78e5cc8 commit c259c07
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/ts-mockito.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function imock<T>(): 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());
Expand Down
25 changes: 18 additions & 7 deletions test/mocking.types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c259c07

Please sign in to comment.