forked from ffMathy/FluffySpoon.JavaScript.Testing.Faking
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresolves.spec.ts
More file actions
49 lines (37 loc) · 1.52 KB
/
Copy pathresolves.spec.ts
File metadata and controls
49 lines (37 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import test from 'ava';
import { Substitute, Arg } from '../src';
interface Calculator {
getMemory(): Promise<number>;
heavyOperation(...args: number[]): Promise<number>;
model: Promise<string>;
}
test('resolves a method with no arguments', async t => {
const calculator = Substitute.for<Calculator>();
calculator.getMemory().resolves(0);
t.is(await calculator.getMemory(), 0);
});
test('resolves a method with arguments', async t => {
const calculator = Substitute.for<Calculator>();
calculator.heavyOperation(0, 1, 1, 2, 3, 5, 8).resolves(13);
t.is(await calculator.heavyOperation(0, 1, 1, 2, 3, 5, 8), 13);
});
test('resolves different values in the specified order on a method', async t => {
const calculator = Substitute.for<Calculator>();
calculator.heavyOperation(Arg.any('number')).resolves(1, 2, 3);
t.is(await calculator.heavyOperation(0), 1);
t.is(await calculator.heavyOperation(0), 2);
t.is(await calculator.heavyOperation(0), 3);
t.is(await calculator.heavyOperation(0), void 0);
});
test('resolves a property', async t => {
const calculator = Substitute.for<Calculator>();
calculator.model.resolves('Casio FX-82');
t.is(await calculator.model, 'Casio FX-82');
});
test('resolves different values in the specified order on a property', async t => {
const calculator = Substitute.for<Calculator>();
calculator.model.resolves('Casio FX-82', 'TI-84 Plus');
t.is(await calculator.model, 'Casio FX-82');
t.is(await calculator.model, 'TI-84 Plus');
t.is(await calculator.model, void 0);
});