Skip to content

Commit e9c8edc

Browse files
committed
test: add choicesFactory scope-empty rule tests
add tests for commitlint 'scope-empty' rule choice builder
1 parent 2ba90df commit e9c8edc

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/prompts/scope-maker.test.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ListQuestion } from 'inquirer';
22
import { Rule, Case, Level, Rules } from '@commitlint/load';
3-
import { scopeMaker, filterFactory, validatorFactory } from './scope-maker';
3+
import { scopeMaker, filterFactory, validatorFactory, choicesFactory } from './scope-maker';
44

55
describe('scopeMaker', () => {
66
describe('validatorFactory', () => {
@@ -54,7 +54,7 @@ describe('scopeMaker', () => {
5454
});
5555

5656
describe('choices', () => {
57-
test('should display choices if array scope enum is present', () => {
57+
it('should display choices if array scope enum is present', () => {
5858
const scopeConfig = scopeMaker([], { 'scope-enum': [2, 'always', ['foo', 'bar']] })[0] as ListQuestion;
5959

6060
if (scopeConfig.choices) {
@@ -76,6 +76,24 @@ describe('scopeMaker', () => {
7676
});
7777
});
7878

79+
describe('choicesFactory', () => {
80+
it('should not allow non-empty scope when empty scope is required', () => {
81+
const scopeConfig = choicesFactory({
82+
'scope-empty': [2, 'always', undefined]
83+
});
84+
85+
expect(scopeConfig).toEqual([{ name: ':skip', value: '' }]);
86+
});
87+
88+
it('should not allow skipping scope when is required', () => {
89+
const scopeConfig = choicesFactory({
90+
'scope-empty': [2, 'never', undefined]
91+
});
92+
93+
expect(scopeConfig).not.toContainEqual({ name: ':skip', value: '' });
94+
});
95+
});
96+
7997
describe('filterFactory', () => {
8098
test.each<[Rule<Case>, string, string]>([
8199
[[Level.Error, 'always', 'camel-case'], 'FOO_BAR', 'fooBar'],

0 commit comments

Comments
 (0)