import test from 'ava'; import { TypeValidation } from '../lib/Types/TypeValidation'; test ('string', async (t) => { const validator = new TypeValidation ('string'); const res = await validator.to_type ('foo'); t.is (res, 'foo'); }); test ('no number', (t) => { const validator = new TypeValidation ('number'); t.throws ( () => validator.to_type ('foo'), { message: 'value is not a number' } ); }); test ('number', async (t) => { const validator = new TypeValidation ('number'); const res = await validator.to_type ('123'); t.is (res, 123); }); test ('no boolean', (t) => { const validator = new TypeValidation ('boolean'); t.throws ( () => validator.to_type ('foo'), { message: 'value is not a boolean' } ); }); test ('boolean', async (t) => { const validator = new TypeValidation ('boolean'); const r1 = await validator.to_type ('false'); const r2 = await validator.to_type ('true'); t.is (r1, false); t.is (r2, true); }); test ('boolean number', async (t) => { const validator = new TypeValidation ('boolean'); const r1 = await validator.to_type (0); const r2 = await validator.to_type (1); t.is (r1, false); t.is (r2, true); });