Skip to content

Commit a02df9d

Browse files
committed
new tests added.
1 parent ff45dc8 commit a02df9d

26 files changed

+64
-615
lines changed

README.md

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,22 @@ More concretely named `@fluffy-spoon/substitute` on NPM is a TypeScript port of
88
Experience full strong-typing of your fakes all the way, and let the TypeScript compiler help with all the dirty work! In the usage example given below, the `exFake` instance is strong-typed all the way, and can be used naturally in a fluent interface!
99

1010
```typescript
11-
import { Substitute } from '@fluffy-spoon/substitute';
11+
import { Substitute, Arg } from '@fluffy-spoon/substitute';
1212

13-
class Example {
14-
a = "1337";
15-
b = 1337;
16-
17-
c(arg1: string, arg2: string) {
18-
return "hello " + arg1 + " world (" + arg2 + ")";
19-
}
20-
21-
get d() {
22-
return 1337;
23-
}
24-
25-
set v(x) {
26-
console.log('define: ' + x);
27-
}
13+
interface Calculator {
14+
add(a: number, b: number): number;
2815
}
2916

30-
var exFake = Substitute.for<Example>();
31-
32-
exFake.a.returns("foo", "bar");
33-
console.log(exFake.a); //prints "foo"
34-
console.log(exFake.a); //prints "bar"
35-
console.log(exFake.a); //prints undefined
36-
37-
exFake.b.returns(10, 30, 99);
38-
console.log(exFake.b); //prints 10
39-
console.log(exFake.b); //prints 30
40-
console.log(exFake.b); //prints 99
41-
console.log(exFake.b); //prints undefined
42-
43-
exFake.c("hi", "there").returns("blah", "haha", "oooh", "lala");
44-
console.log(exFake.c("hi", "there")); //prints "blah"
45-
console.log(exFake.c("hi", "there")); //prints "haha"
46-
console.log(exFake.c("hi", "the1re")); //prints undefined (since it doesn't match the parameters)
47-
console.log(exFake.c("hi", "there")); //prints "ooh"
48-
console.log(exFake.c("something", "there")); //prints undefined (since it doesn't match the parameters)
49-
50-
exFake.d.returns(9);
51-
console.log(exFake.d); //prints 9
17+
//Create:
18+
var calculator = Substitute.for<Calculator>();
19+
20+
//Set a return value:
21+
calculator.add(1, 2).returns(3);
22+
23+
//Check received calls:
24+
calculator.received().add(1, Arg.any());
25+
calculator.didNotReceive().add(2, 2);
5226
```
5327

54-
## But how?
28+
## What is this - black magic?
5529
`@fluffy-spoon/substitute` works the same way that NSubstitute does, except that it uses the EcmaScript 6 `Proxy` class to produce the fakes. You can read more about how NSubstitute works to get inspired.

dist/spec/index.test.d.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

dist/spec/index.test.js

Lines changed: 0 additions & 74 deletions
This file was deleted.

dist/spec/index.test.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/src/Arguments.d.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

dist/src/Arguments.js

Lines changed: 0 additions & 42 deletions
This file was deleted.

dist/src/Arguments.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/src/Context.d.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)