/* * 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 , October 2020 */ import { PathType } from '../../lib/TypeValidation/PathType'; describe ('paths', () => { it ('no file', async () => { const validator = new PathType ('file'); await expectAsync ( validator.to_type ('test') ) .toBeRejectedWithError ('cannot assign folder to file'); }); it ('file', async () => { const validator = new PathType ('file'); const res = await validator.to_type ('package.json'); expect (res) .toEqual ('package.json'); }); it ('no folder', async () => { const validator = new PathType ('folder'); await expectAsync (validator.to_type ('package.json')) .toBeRejectedWithError ('cannot assign folder to file'); }); it ('folder', async () => { const validator = new PathType ('folder'); const res = await validator.to_type ('test'); expect (res) .toEqual ('test'); }); it ('no path', async () => { const validator = new PathType ('path'); await expectAsync (validator.to_type ('doesnotexist.file')) .toBeRejectedWithError ('path does not exist'); }); it ('path', async () => { const validator = new PathType ('path'); const res = await validator.to_type ('test'); expect (res) .toEqual ('test'); }); });