From 62b5a52e93af91c7d3aefcaeb9955f100e2ee841 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sat, 13 Jul 2019 12:25:09 +1200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20create=20`tryGetChildNode?= =?UTF-8?q?`=20util=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/util.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) 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(); +};