Skip to content

Commit

Permalink
fixup! refactor: test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
himself65 committed Sep 7, 2022
1 parent 5e8a76e commit 5ba57da
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 36 deletions.
36 changes: 0 additions & 36 deletions test/parallel/test-parse-args-required-options.mjs

This file was deleted.

75 changes: 75 additions & 0 deletions test/parallel/test-parse-args.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -823,3 +823,78 @@ test('tokens: strict:false with -- --', () => {
const { tokens } = parseArgs({ strict: false, args, tokens: true });
assert.deepStrictEqual(tokens, expectedTokens);
});

test('strict: required option', () => {
const args = ['--foo']
parseArgs({
args,
options: {
foo: {
type: 'boolean',
required: true
}
}
})
})

test('required option', () => {
const args = ['--foo', '--goo']
parseArgs({
strict: false,
args,
options: {
foo: {
type: 'boolean',
required: true
}
}
})
})

test('strict: false required option fail', () => {
const args = []
assert.throws(() => {
parseArgs({
strict: false,
args,
options: {
foo: {
type: 'boolean',
required: true
}
}
}, {
code: 'ERR_PARSE_ARGS_REQUIRED_OPTION_VALUE'
})
})
})

test('strict: no input but has required option', () => {
const args = []
assert.throws(() => {
parseArgs({
args,
options: {
foo: {
type: 'boolean',
required: true
}
}
}, {
code: 'ERR_PARSE_ARGS_REQUIRED_OPTION_VALUE'
})
})
})

test('strict: no input and no required option', () => {
const args = []
parseArgs({
args,
options: {
foo: {
type: 'boolean',
required: false
}
}
})
})

0 comments on commit 5ba57da

Please sign in to comment.