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 Mar 21, 2018
1 parent 945b985 commit b023fac
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 @@ -42,7 +42,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 b023fac

Please sign in to comment.