Skip to content

Commit

Permalink
Added spec for mocking object property, spec given/when/then sections…
Browse files Browse the repository at this point in the history
… fixed
  • Loading branch information
NagRock committed Mar 13, 2017
1 parent 37dfa8a commit b27809d
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions test/mocking.getter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import {mock, instance, when} from "../src/ts-mockito";
import {Bar} from "./utils/Bar";
import {MethodToStub} from "../src/MethodToStub";

describe('mocking', () => {
describe("mocking", () => {
let mockedFoo: FooWithGetterAndSetter;
let foo: FooWithGetterAndSetter;

describe('mocking object with getters and setters', () => {
it('does not execute getter or setter code (not throwing null pointer exception)', () => {
describe("mocking object with getters and setters", () => {
it("does not execute getter or setter code (not throwing null pointer exception)", () => {
// given

// when
Expand All @@ -18,7 +18,7 @@ describe('mocking', () => {

});

it('does create own property descriptors on mock', () => {
it("does create own property descriptors on mock", () => {
// given

// when
Expand All @@ -28,41 +28,51 @@ describe('mocking', () => {
expect(<any>mockedFoo.twoPlusTwo instanceof MethodToStub).toBe(true);
});

it('does create own property descriptors on instance', () => {
it("does create own property descriptors on instance", () => {
// given
mockedFoo = mock(FooWithGetterAndSetter);
foo = instance(mockedFoo);

// when
when(mockedFoo.sampleString).thenReturn("sampleString");

// then
expect(foo.sampleString).toBe("sampleString");
});

it("does create own property descriptors on instance", () => {
// given
mockedFoo = mock(FooWithGetterAndSetter);
foo = instance(mockedFoo);

// when
when(mockedFoo.twoPlusTwo).thenReturn(42);

// then
expect(foo.twoPlusTwo).toBe(42);
});

it('does create inherited property descriptors on mock', () => {
it("does create inherited property descriptors on mock", () => {
// given

// when
mockedFoo = mock(FooWithGetterAndSetter);
foo = instance(mockedFoo);

// when

// then
expect(<any>mockedFoo.sampleString instanceof MethodToStub).toBe(true);
});

it('does create inherited property descriptors on instance', () => {
it("does create inherited property descriptors on instance", () => {
// given

// when
mockedFoo = mock(FooWithGetterAndSetter);
foo = instance(mockedFoo);

when(mockedFoo.sampleString).thenReturn('42');
// when
when(mockedFoo.sampleString).thenReturn("42");

// then
expect(foo.sampleString).toBe('42');
expect(foo.sampleString).toBe("42");
});
});

Expand All @@ -80,6 +90,8 @@ describe('mocking', () => {
});

abstract class SampleAbstractClass {
public sampleField: string;

public get sampleString(): string {
return "sampleString";
}
Expand Down

0 comments on commit b27809d

Please sign in to comment.