Skip to content

Commit b2392f7

Browse files
committed
fix: allow 0 for integer values in askForOptionalInteger
1 parent a471d47 commit b2392f7

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

.changeset/metal-terms-eat.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@smartthings/cli-lib": patch
3+
"@smartthings/cli": patch
4+
---
5+
6+
fixed bug where prompts for optional integers were treating 0 as if no value was entered

packages/lib/src/__tests__/user-query.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,14 @@ describe('askForOptionalInteger', () => {
203203
expect(promptMock).toHaveBeenCalledTimes(1)
204204
})
205205

206+
it('returns "0" entered as 0', async () => {
207+
promptMock.mockResolvedValue({ value: '0' })
208+
209+
expect(await askForOptionalInteger('prompt message')).toBe(0)
210+
211+
expect(promptMock).toHaveBeenCalledTimes(1)
212+
})
213+
206214
it('passes validate to inquirer', async () => {
207215
promptMock.mockResolvedValue({ value: '' })
208216

packages/lib/src/user-query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export const askForOptionalInteger = async (message: string, options?: AskForInt
124124
...options,
125125
validate: options?.validate ? allowEmptyFn(options.validate) : undefined,
126126
}
127-
return await promptForInteger(message, updatedOptions) || undefined
127+
return await promptForInteger(message, updatedOptions)
128128
}
129129

130130
/**

0 commit comments

Comments
 (0)