/
validateBeforePrepare.spec.js
49 lines (42 loc) · 1.59 KB
/
validateBeforePrepare.spec.js
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 validate from '../validateBeforePrepare';
import { isWorkingTreeClean, getCurrentBranch } from 'shipjs-lib';
const defaultOpts = {
baseBranches: ['master'],
};
describe('Validate', () => {
beforeEach(() => {
isWorkingTreeClean.mockImplementation(() => true);
getCurrentBranch.mockImplementation(() => 'master');
});
it('returns error if working tree is not clean', () => {
isWorkingTreeClean.mockImplementation(() => false);
const result = validate(defaultOpts);
expect(result).not.toBe(true);
expect(result.length).toBe(1);
expect(result[0]).toMatchInlineSnapshot(`"workingTreeNotClean"`);
});
it('does not return error if working tree is clean', () => {
isWorkingTreeClean.mockImplementation(() => true);
const result = validate(defaultOpts);
expect(result).toBe(true);
});
it('returns error if current branch is not correct', () => {
getCurrentBranch.mockImplementation(() => 'aaa');
const result = validate(defaultOpts);
expect(result).not.toBe(true);
expect(result.length).toBe(1);
expect(result[0]).toMatchInlineSnapshot(`"currentBranchIncorrect"`);
});
it('does not return error if current branch is correct', () => {
getCurrentBranch.mockImplementation(() => 'master');
const result = validate(defaultOpts);
expect(result).toBe(true);
});
it('returns more than one error', () => {
isWorkingTreeClean.mockImplementation(() => false);
getCurrentBranch.mockImplementation(() => 'aaa');
const result = validate(defaultOpts);
expect(result).not.toBe(true);
expect(result.length).toBe(2);
});
});