-
Notifications
You must be signed in to change notification settings - Fork 0
/
robot.spec.ts
81 lines (67 loc) · 2.4 KB
/
robot.spec.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import 'reflect-metadata';
import { describe } from 'mocha';
import * as sinon from 'sinon';
import * as chai from 'chai';
import { Robot, IRobot } from './robot';
import { IHelloService } from './service/helloService';
import { container } from './inversify.config';
import { TYPES } from './constant/types';
const helloService = container.get<IHelloService>(TYPES.HelloService);
let robot: IRobot;
describe('robot test', function () {
describe('spy test', function () {
let helloSpy: sinon.SinonSpy;
before(function () {
helloSpy = sinon.spy(helloService, 'hello');
robot = new Robot(helloService);
});
after(function () {
sinon.restore();
})
it('test', function () {
const name = 'yogae';
const res = robot.start(name);
chai.expect(res.startsWith('hello')).to.be.equal(true);
chai.expect(helloSpy.calledOnce).to.be.equal(true);
const [argName] = helloSpy.getCall(0).args;
chai.expect(argName).to.be.equal(name);
});
});
describe('stub test', function () {
let helloStub: sinon.SinonStub;
before(function () {
helloStub = sinon.stub(helloService, 'hello').returns('stubhello');
robot = new Robot(helloService);
});
after(function () {
sinon.restore();
})
it('test', function () {
const name = 'yogae';
const res = robot.start(name);
chai.expect(res).to.be.equal('stubhello');
chai.expect(helloStub.calledOnce).to.be.equal(true);
const [argName] = helloStub.getCall(0).args;
chai.expect(argName).to.be.equal(name);
});
});
describe('mock test', function () {
let helloMock: sinon.SinonMock;
let helloExpection: sinon.SinonExpectation;
before(function () {
helloMock = sinon.mock(helloService);
helloExpection = helloMock.expects('hello');
robot = new Robot(helloService);
});
after(function () {
sinon.restore();
})
it('test', function () {
const name = 'yogae';
const res = robot.start(name);
const [argName] = helloExpection.getCall(0).args;
chai.expect(argName).to.be.equal(name);
helloMock.verify();
});
});
});