Skip to content

Commit

Permalink
Merge branch 'master' into not
Browse files Browse the repository at this point in the history
  • Loading branch information
cakeinpanic committed Jan 23, 2018
2 parents 4f4ed84 + c632a41 commit 8c542fb
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
13 changes: 12 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,23 @@ module.exports = function (config) {

reporters: ["progress", "mocha"],

browsers: ["ChromeHeadless", "PhantomJS"],
browsers: ["CustomChromeHeadless", "PhantomJS"],

mochaReporter: {
output: 'minimal'
},

customLaunchers: {
'CustomChromeHeadless': {
base: 'ChromeHeadless',
flags: [
'--no-sandbox',
'--disable-setuid-sandbox'
],
debug: true
}
},

logLevel: config.LOG_INFO,
autoWatch: true,
singleRun: false
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-mockito",
"version": "2.2.7",
"version": "2.2.8",
"description": "Mocking library for TypeScript",
"main": "lib/ts-mockito.js",
"typings": "lib/ts-mockito",
Expand Down
4 changes: 4 additions & 0 deletions src/Mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export class Mocker {
private objectPropertyCodeRetriever = new ObjectPropertyCodeRetriever();

constructor(private clazz: any, protected instance: any = {}) {
if (typeof Proxy !== "undefined") {
this.instance = new Proxy(this.instance, this.createCatchAllHandlerForRemainingPropertiesWithoutGetters());
}

this.mock.__tsmockitoInstance = this.instance;
this.mock.__tsmockitoMocker = this;
if (_.isObject(this.clazz) && _.isObject(this.instance)) {
Expand Down
7 changes: 1 addition & 6 deletions src/ts-mockito.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,7 @@ export function when<T>(method: T): MethodStubSetter<T> {

export function instance<T>(mockedValue: T): T {
const tsmockitoInstance = (mockedValue as any).__tsmockitoInstance as T;
if (typeof Proxy === "undefined") {
return tsmockitoInstance;
}

const tsmockitoMocker = (mockedValue as any).__tsmockitoMocker as Mocker;
return new Proxy(tsmockitoInstance as any, tsmockitoMocker.createCatchAllHandlerForRemainingPropertiesWithoutGetters());
return tsmockitoInstance;
}

export function capture<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>(method: (a: T0, b: T1, c: T2, d: T3, e: T4, f: T5, g: T6, h: T7, i: T8, j: T9) => any): ArgCaptor10<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>;
Expand Down
20 changes: 20 additions & 0 deletions test/instance.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {instance, mock} from "../src/ts-mockito";
import {Foo} from "./utils/Foo";

describe("instance", () => {
describe("getting instance of mock", () => {
let mockedFoo: Foo;

it("returns always same instance", () => {
// given
mockedFoo = mock(Foo);

// when
const firstFooInstance = instance(mockedFoo);
const secondFooInstance = instance(mockedFoo);

// then
expect(firstFooInstance).toBe(secondFooInstance);
});
});
});

0 comments on commit 8c542fb

Please sign in to comment.