Skip to content

Commit fc06920

Browse files
committed
Cleanup tests
1 parent 6eebd44 commit fc06920

File tree

1 file changed

+33
-43
lines changed

1 file changed

+33
-43
lines changed

index.test.js

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,66 +7,56 @@ const {expect} = chai;
77
chai.use(sinonChai);
88

99
describe(`prompter`, () => {
10-
let inquirer, commit, prompter;
11-
beforeEach(() => {
12-
inquirer = {prompt: sinon.spy()};
10+
let inquirer, commit, prompter, commitAnswers;
11+
12+
before(() => {
1313
commit = sinon.spy();
14+
inquirer = {prompt: sinon.spy()};
1415
prompter = proxyquire('./', {inquirer}).prompter;
1516
});
1617

17-
it(`call inquirer.prompt`, () => {
18-
prompter(inquirer);
19-
expect(inquirer.prompt).to.have.been.calledWith(sinon.match.array, sinon.match.func);
18+
beforeEach(() => {
19+
prompter(null, commit);
20+
commitAnswers = inquirer.prompt.getCall(0).args[1];
2021
});
2122

22-
describe(`commitAnswers`, () => {
23-
let commitAnswers;
24-
beforeEach(() => {
25-
prompter(inquirer, commit);
26-
commitAnswers = inquirer.prompt.getCall(0).args[1];
27-
});
23+
it(`should call commit with the proper message`, () => {
24+
const message = 'sample commit message';
25+
const issues = 'CZ-234 CZ-235';
26+
const workflow = 'closed';
27+
const time = '3y 2w 7d 8h 30m';
28+
const comment = 'This took waaaaay too long';
29+
commitAnswers({message, issues, workflow, time, comment});
30+
expect(commit).to.have.been.calledWith([
31+
message,
32+
issues,
33+
`#${workflow}`,
34+
`#time ${time}`,
35+
`#comment ${comment}`
36+
].join(' '));
37+
});
2838

29-
it(`should call commit with the proper message`, () => {
39+
['workflow', 'time', 'comment'].forEach((item) => {
40+
it(`should just leave off ${item} if it's not specified`, () => {
3041
const message = 'sample commit message';
3142
const issues = 'CZ-234 CZ-235';
3243
const workflow = 'closed';
3344
const time = '3y 2w 7d 8h 30m';
3445
const comment = 'This took waaaaay too long';
35-
commitAnswers({message, issues, workflow, time, comment});
36-
expect(commit).to.have.been.calledWith([
46+
const answers = {message, issues, workflow, time, comment};
47+
delete answers[item];
48+
commitAnswers(answers);
49+
expect(commit).to.have.been.calledWith(filter([
3750
message,
3851
issues,
39-
`#${workflow}`,
40-
`#time ${time}`,
41-
`#comment ${comment}`
42-
].join(' '));
52+
item !== 'workflow' ? `#${workflow}` : undefined,
53+
item !== 'time' ? `#time ${time}` : undefined,
54+
item !== 'comment' ? `#comment ${comment}` : undefined
55+
]).join(' '));
4356
});
44-
45-
['workflow', 'time', 'comment'].forEach((item) => {
46-
it(`should just leave off ${item} if it's not specified`, () => {
47-
const message = 'sample commit message';
48-
const issues = 'CZ-234 CZ-235';
49-
const workflow = 'closed';
50-
const time = '3y 2w 7d 8h 30m';
51-
const comment = 'This took waaaaay too long';
52-
const answers = {message, issues, workflow, time, comment};
53-
delete answers[item];
54-
commitAnswers(answers);
55-
expect(commit).to.have.been.calledWith(filter([
56-
message,
57-
issues,
58-
item !== 'workflow' ? `#${workflow}` : undefined,
59-
item !== 'time' ? `#time ${time}` : undefined,
60-
item !== 'comment' ? `#comment ${comment}` : undefined
61-
]).join(' '));
62-
});
63-
})
6457
});
65-
6658
});
6759

6860
function filter(array) {
69-
return array.filter(function(item) {
70-
return !!item;
71-
});
61+
return array.filter(Boolean);
7262
}

0 commit comments

Comments
 (0)