Skip to content

Commit

Permalink
Removed wrong spec for mocking fields, its not working yet. Added rea…
Browse files Browse the repository at this point in the history
…dme for stubbing getters
  • Loading branch information
NagRock committed Mar 13, 2017
1 parent b27809d commit 5a7e831
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ console.log(foo.getBar(3));
console.log(foo.getBar(999));
```

### Stubbing getter value

```
// Creating mock
let mockedFoo:Foo = mock(Foo);
// stub getter before execution
when(mockedFoo.sampleGetter).thenReturn('three');
// Getting instance
let foo:Foo = instance(mockedFoo);
// prints three
console.log(foo.sampleGetter);
```

### Call count verification

``` typescript
Expand Down Expand Up @@ -280,3 +296,4 @@ console.log(foo.getBar(2)); // null - no more behaviors for arg === 2 defined
* Szczepan Faber (https://www.linkedin.com/in/szczepiq)
* Sebastian Konkol (https://www.linkedin.com/in/sebastiankonkol)
* Clickmeeting (http://clickmeeting.com)
* Thomas Hilzendegen (https://github.com/thomashilzendegen)
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": "1.1.5",
"version": "1.2.0",
"description": "",
"main": "lib/ts-mockito.js",
"typings": "lib/ts-mockito",
Expand Down
14 changes: 0 additions & 14 deletions test/mocking.getter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@ describe("mocking", () => {
expect(<any>mockedFoo.twoPlusTwo instanceof MethodToStub).toBe(true);
});

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);
Expand Down Expand Up @@ -90,8 +78,6 @@ describe("mocking", () => {
});

abstract class SampleAbstractClass {
public sampleField: string;

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

0 comments on commit 5a7e831

Please sign in to comment.