-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
49 lines (36 loc) · 1.27 KB
/
index.ts
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
const assert = require('assert');
import ClassMocker from "./src/ClassMocker";
class Main {
public static run(): void {
process.stdin.resume();
const car = ClassMocker.mockClass<Car>(Car);
car.mock().method('start').willReturn('the mocked return value');
const result = test(car);
test(car);
assert.equal(result, 'the mocked return value');
assert.equal(car.mock().method('start').wasCalledTimes(2), true);
assert.equal(car.mock().method('start').wasCalledWith(undefined), true);
assert.equal(car.mock().method('fuelUp').wasCalledWith(1000), true);
assert.equal(car.mock().method('fuelUp').wasCalledWith(500, 1), true);
assert.equal(car.mock().method('fuelUp').wasCalledWith(1000, 2), true);
assert.equal(car.mock().method('fuelUp').wasCalledWith(500, 3), true);
assert.equal(car.mock().method('fuelUp').amountOfCalls(), 4);
}
}
class Car {
public start() {
return 'start';
}
public what() {
return 'what';
}
public fuelUp(fuelQuantity: number): string {
return 'good for the next ' + fuelQuantity / 5 + ' hours';
}
}
function test(car: Car) {
car.fuelUp(1000);
car.fuelUp(500);
return car.start();
}
Main.run();