Skip to content

Commit

Permalink
fix: πŸ› create tryGetChildNode util function
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Jul 13, 2019
1 parent 81a564f commit 62b5a52
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions 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);
Expand All @@ -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();
};

0 comments on commit 62b5a52

Please sign in to comment.