diff --git a/src/__tests__/util.ts b/src/__tests__/util.ts index d501be5a..8e8500d7 100644 --- a/src/__tests__/util.ts +++ b/src/__tests__/util.ts @@ -1,4 +1,5 @@ import { createFsFromVolume, Volume } from '..'; +import { Link, Node } from '../node'; export const create = (json: { [s: string]: string } = { '/foo': 'bar' }) => { const vol = Volume.fromJSON(json); @@ -8,3 +9,13 @@ export const create = (json: { [s: string]: string } = { '/foo': 'bar' }) => { export const createFs = (json?) => { return createFsFromVolume(create(json)); }; + +export const tryGetChildNode = (link: Link, name: string): Node => { + const child = link.getChild(name); + + if (!child) { + throw new Error(`expected link to have a child named "${name}"`); + } + + return child.getNode(); +};