Repository navigation
Expand file tree
/
Copy pathmain.ts
More file actions
75 lines (73 loc) · 2.1 KB
/
Copy pathmain.ts
File metadata and controls
75 lines (73 loc) · 2.1 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
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
import * as registerSuite from 'intern!object';
import * as assert from 'intern/chai!assert';
import { stub, SinonStub } from 'sinon';
import command, { MyContext, MyArgv } from './../../src/main';
import { Helper } from './../../src/interfaces';
import { getHelperStub } from '../support/testHelper';
let optionStub: SinonStub;
let helperStub: Helper;
let consoleStub: SinonStub;
const testContextMessage = 'test';
registerSuite({
name: 'main',
'Should contain a description'() {
assert.isTrue(command.description !== undefined);
assert.isTrue(typeof command.description === 'string');
},
'Should contain a register function'() {
assert.isTrue(command.register !== undefined);
assert.isTrue(typeof command.register === 'function');
},
'Should contain a run function'() {
assert.isTrue(command.run !== undefined);
assert.isTrue(typeof command.run === 'function');
},
'register': {
'beforeEach'() {
helperStub = getHelperStub<MyContext>();
helperStub.context = {};
optionStub = stub(helperStub.yargs, 'option');
},
'afterEach'() {
optionStub.restore();
},
'Should set context message'() {
command.register(helperStub);
assert.equal('Hello World!', helperStub.context.message);
},
'Should call yargs.option'() {
command.register(helperStub);
assert.isTrue(optionStub.calledOnce);
},
'Should return yargs'() {
const yargsResponse = command.register(helperStub);
assert.equal(helperStub.yargs, yargsResponse);
}
},
'run': {
'beforeEach'() {
helperStub = getHelperStub<MyContext>();
helperStub.context = {
message: testContextMessage
};
consoleStub = stub(console, 'log');
},
'afterEach'() {
consoleStub.restore();
},
'Should log out context message'() {
const args = {};
return command.run(helperStub, <MyArgv> args).then(() => {
assert.isTrue(consoleStub.calledWith(testContextMessage));
});
},
'Should shout out context message'() {
const args = {
shout: true
};
return command.run(helperStub, <MyArgv> args).then(() => {
assert.isTrue(consoleStub.calledWith(testContextMessage.toUpperCase()));
});
}
}
});