Skip to content

Commit c259c07

Browse files
Throwing an Error when calling imock() without Proxy support
1 parent 78e5cc8 commit c259c07

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/ts-mockito.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function imock<T>(): T {
4040
const mockedValue = new Mocker(Empty, true).getMock();
4141

4242
if (typeof Proxy === "undefined") {
43-
return mockedValue;
43+
throw new Error("Mocking of interfaces requires support for Proxy objects");
4444
}
4545
const tsmockitoMocker = mockedValue.__tsmockitoMocker;
4646
return new Proxy(mockedValue, tsmockitoMocker.createCatchAllHandlerForRemainingPropertiesWithoutGetters());

test/mocking.types.spec.ts

+18-7
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,29 @@ describe("mocking", () => {
157157
let mockedFoo: SampleInterface;
158158
let foo: SampleInterface;
159159

160-
it("can create interface mock", () => {
161-
// given
160+
if (typeof Proxy === "undefined") {
161+
it("throws when creating interface mock", () => {
162+
// given
162163

163-
// when
164-
mockedFoo = imock();
165-
foo = instance(mockedFoo);
164+
// when
166165

167-
// then
168-
});
166+
// then
167+
expect(() => imock()).toThrow();
168+
});
169+
}
169170

170171
if (typeof Proxy !== "undefined") {
171172

173+
it("can create interface mock", () => {
174+
// given
175+
176+
// when
177+
mockedFoo = imock();
178+
foo = instance(mockedFoo);
179+
180+
// then
181+
});
182+
172183
it("can verify call count", () => {
173184
// given
174185
mockedFoo = imock();

0 commit comments

Comments
 (0)