/* * Copyright (C) Sapphirecode - All Rights Reserved * This file is part of console-app which is released under MIT. * See file 'LICENSE' for full license details. * Created by Timo Hocker , May 2020 */ import test from 'ava'; import { PathType } from '../lib/Types/PathType'; test ('no file', async (t) => { const validator = new PathType ('file'); await t.throwsAsync ( () => validator.to_type ('test'), { message: 'cannot assign folder to file' } ); }); test ('file', async (t) => { const validator = new PathType ('file'); const res = await validator.to_type ('package.json'); t.is (res, 'package.json'); }); test ('no folder', async (t) => { const validator = new PathType ('folder'); await t.throwsAsync ( () => validator.to_type ('package.json'), { message: 'cannot assign folder to file' } ); }); test ('folder', async (t) => { const validator = new PathType ('folder'); const res = await validator.to_type ('test'); t.is (res, 'test'); }); test ('no path', async (t) => { const validator = new PathType ('path'); await t.throwsAsync ( () => validator.to_type ('doesnotexist.file'), { message: 'path does not exist' } ); }); test ('path', async (t) => { const validator = new PathType ('path'); const res = await validator.to_type ('test'); t.is (res, 'test'); });