Skip to content

Commit

Permalink
add findDeepestParent tests
Browse files Browse the repository at this point in the history
  • Loading branch information
talentlessguy committed Feb 4, 2024
1 parent fa8bcb3 commit ab0a1e7
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion utils_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { describe, it } from 'https://deno.land/[email protected]/testing/bdd.ts'
import { expect } from 'https://deno.land/[email protected]/expect/mod.ts'
import { findExactCommand, hasOptions, helpMessageForCommand } from './utils.ts'
import {
findDeepestParent,
findExactCommand,
hasOptions,
helpMessageForCommand,
} from './utils.ts'
import { CLI } from './clif.ts'

describe('hasOptions', () => {
Expand Down Expand Up @@ -100,3 +105,27 @@ describe('helpMessageForCommand', () => {
expect(message).toEqual('Usage: test [args]\n --test, -t \n')
})
})

describe('findDeepestParent', () => {
it('returns a cli if it has no parent', () => {
const cli = new CLI({ name: 'cli' })

expect(findDeepestParent(cli)).toEqual(cli)
})
it('returns a parent cli if it has a parent', () => {
const cli = new CLI({ name: 'cli' })

const child = cli.program('child')

expect(findDeepestParent(child)).toEqual(cli)
})
it('returns the deepest cli if it has multiple parents', () => {
const cli = new CLI({ name: 'cli' })

const child = cli.program('child')

const grandchild = child.program('grandchild')

expect(findDeepestParent(grandchild)).toEqual(cli)
})
})

0 comments on commit ab0a1e7

Please sign in to comment.