Skip to content

Commit 9cf843c

Browse files
committed
Fix: check for whitespaces in scope
1 parent b726219 commit 9cf843c

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/questions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ const questions = (config) => {
3333
name: 'scope',
3434
message: 'Enter your scope (no whitespaces allowed):',
3535
when: () => config.questions.scope,
36-
filter: answers => (answers ? `(${answers})` : answers),
36+
validate: input => (input.match(/\s/) !== null ? 'No whitespaces allowed' : true),
37+
filter: input => (input ? `(${input})` : input),
3738
},
3839
{
3940
type: 'input',

test/questions.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,22 @@ test('check if scope is off by default', (t) => {
9292
t.is(questionsList[1].when(), false);
9393
});
9494

95-
test('check if scope validates correctly', (t) => {
95+
test('check if scope filters correctly', (t) => {
9696
const config = getConfig();
9797
const questionsList = questions(config);
9898

9999
t.is(questionsList[1].filter('answer'), '(answer)');
100100
t.is(questionsList[1].filter(''), '');
101101
});
102102

103+
test('check if scope validates correctly', (t) => {
104+
const config = getConfig();
105+
const questionsList = questions(config);
106+
107+
t.is(questionsList[1].validate('not correct'), 'No whitespaces allowed');
108+
t.is(questionsList[1].validate('correct'), true);
109+
});
110+
103111
test('validate functions in questions', (t) => {
104112
const config = getConfig();
105113
const questionsList = questions(config);

0 commit comments

Comments
 (0)