Skip to content

Commit

Permalink
Revert "Merge pull request #18 from TypeStrong/15-combinelatest-as-fu…
Browse files Browse the repository at this point in the history
…nction-issue"

This reverts commit 1e2cd43, reversing
changes made to 426058d.
  • Loading branch information
johanblumenberg committed Aug 12, 2022
1 parent 281d8d6 commit 7008c8e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 24 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
},
"author": "[email protected]",
"contributors": [
"Andrew Bradley <[email protected]>",
"Liron Hazan"
"Andrew Bradley <[email protected]>"
],
"license": "MIT",
"repository": {
Expand Down
9 changes: 4 additions & 5 deletions src/Mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {strictEqual} from "./ts-mockito";
import {MockableFunctionsFinder} from "./utils/MockableFunctionsFinder";
import {ObjectInspector} from "./utils/ObjectInspector";
import {ObjectPropertyCodeRetriever} from "./utils/ObjectPropertyCodeRetriever";
import { TODO } from "./utils/types";

export class Mocker {
public mock: any = {};
Expand All @@ -20,15 +21,13 @@ export class Mocker {
private excludedPropertyNames: string[] = ["hasOwnProperty"];
private defaultedPropertyNames: string[] = ["Symbol(Symbol.toPrimitive)", "then", "catch"];

constructor(private clazz: any, public instance: any = {}, isSpy: boolean = false) {
constructor(private clazz: any, public instance: any = {}) {
this.mock.__tsmockitoInstance = this.instance;
this.mock.__tsmockitoMocker = this;
if (_.isObject(this.clazz) && _.isObject(this.instance)) {
this.processProperties((this.clazz as any).prototype);
if (!isSpy || typeof Proxy === "undefined") {
this.processClassCode(this.clazz);
this.processFunctionsCode((this.clazz as any).prototype);
}
this.processClassCode(this.clazz);
this.processFunctionsCode((this.clazz as any).prototype);
}
if (typeof Proxy !== "undefined" && this.clazz) {
this.mock.__tsmockitoInstance = new Proxy(this.instance, this.createCatchAllHandlerForRemainingPropertiesWithoutGetters());
Expand Down
2 changes: 1 addition & 1 deletion src/Spy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class Spy extends Mocker {
private realMethods: { [key: string]: RealMethod };

constructor(instance: any) {
super(instance.constructor, instance, true);
super(instance.constructor, instance);

if (_.isObject(instance)) {
this.processProperties(instance);
Expand Down
16 changes: 0 additions & 16 deletions test/spy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,10 @@ import {capture, reset, spy, verify, when} from "../src/ts-mockito";

describe("spying on a real object", () => {
class Real {
public dynamicMethod: Function;
public dynamicMethodInFunction: Function;
public b = 11;

constructor() {
this.dynamicMethod = () => "dynamicMethod";
}

get baz() {
return 3;
}

public getBar(): string {
this.dynamicMethodInFunction = () => "dynamicMethodInFunction";
return "bar";
}
public foo(a: number) {
return a;
}
Expand Down Expand Up @@ -67,10 +55,6 @@ describe("spying on a real object", () => {

// then
expect(foo.bar()).toBe(2);
expect(foo.getBar()).toBe("bar");
expect(foo.dynamicMethod()).toBe("dynamicMethod");
expect(foo.dynamicMethodInFunction()).toBe("dynamicMethodInFunction");

});
});

Expand Down

0 comments on commit 7008c8e

Please sign in to comment.