forked from conventional-changelog/commitlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubject-exclamation-mark.test.ts
57 lines (47 loc) · 1.66 KB
/
subject-exclamation-mark.test.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
import parse from '@commitlint/parse';
import {subjectExclamationMark} from './subject-exclamation-mark';
const preset = require('conventional-changelog-angular');
const parseMessage = async (str: string) => {
const {parserOpts} = await preset;
return parse(str, undefined, parserOpts);
};
const messages = {
empty: 'test:\n',
with: `test!: subject\n`,
without: `test: subject\n`,
};
const parsed = {
empty: parseMessage(messages.empty),
with: parseMessage(messages.with),
without: parseMessage(messages.without),
};
test('empty against "always" should fail', async () => {
const [actual] = subjectExclamationMark(await parsed.empty, 'always');
const expected = false;
expect(actual).toEqual(expected);
});
test('empty against "never" should succeed', async () => {
const [actual] = subjectExclamationMark(await parsed.empty, 'never');
const expected = true;
expect(actual).toEqual(expected);
});
test('with against "always" should succeed', async () => {
const [actual] = subjectExclamationMark(await parsed.with, 'always');
const expected = true;
expect(actual).toEqual(expected);
});
test('with against "never" should fail', async () => {
const [actual] = subjectExclamationMark(await parsed.with, 'never');
const expected = false;
expect(actual).toEqual(expected);
});
test('without against "always" should fail', async () => {
const [actual] = subjectExclamationMark(await parsed.without, 'always');
const expected = false;
expect(actual).toEqual(expected);
});
test('without against "never" should succeed', async () => {
const [actual] = subjectExclamationMark(await parsed.without, 'never');
const expected = true;
expect(actual).toEqual(expected);
});