All files / src/toArgs convertNonCommands.test.js

0% Statements 0/26
100% Branches 0/0
0% Functions 0/4
0% Lines 0/26

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                                                                                             
const {convertNonCommands} = require('./convertNonCommands')
 
test('convertNonCommands works as expected', () => {
  const name     = {key: 'name', types: ['string'], args: ['--name'], values: ['Logan']}
  const address  = {key: 'name', types: ['number', 'string'], args: ['--address'], values: [38100, 'Braunschweig']}
  const question = {key: 'question', types: ['string'], args: ['-q'], values: ["What's your lastname?"]}
  const jokingly = {key: 'jokingly', types: [], args: ['-j'], defaultValue: [1]}
  const ask      = {key: 'ask', args: ['ask'], opts: [question, jokingly]}
  const variadic = {key: 'variadic', values: ['1', '2']}
  const weird    = {key: 'weird', types: null, values: ['1', '2']}
  const opts     = [ask, name, address, variadic, weird]
 
  const {errs, args} = convertNonCommands({opts})
 
  const expArgs = {
    _: [],
    name: 'Logan',
    variadic: ['1', '2']
  }
 
  const expErrs = []
 
  expect(args).toStrictEqual(expArgs)
  expect(errs).toStrictEqual(expErrs)
})
 
test('convertNonCommands works if opts is undefined', () => {
  const obj = {}
 
  const {args} = convertNonCommands(obj)
 
  expect(args).toStrictEqual({_: []})
})
 
test('convertNonCommands works if input is undefined', () => {
  const {args} = convertNonCommands()
 
  expect(args).toStrictEqual({_: []})
})
 
test('convertNonCommands passes on errors', () => {
  const ERRS = ['foo']
 
  const {errs} = convertNonCommands({errs: ERRS})
 
  expect(errs).toStrictEqual(ERRS)
})