console-app/test/PathType.ts
2020-05-09 19:51:43 +02:00

40 lines
1.1 KiB
TypeScript

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');
});