Added some tests

This commit is contained in:
Angelos Chalaris
2018-01-28 16:28:54 +02:00
parent 5358f1b908
commit 06d7e04220
19 changed files with 257 additions and 33 deletions

8
test/attempt/attempt.js Normal file
View File

@ -0,0 +1,8 @@
const attempt = (fn, ...args) => {
try {
return fn(args);
} catch (e) {
return e instanceof Error ? e : new Error(e);
}
};
module.exports = attempt

View File

@ -0,0 +1,15 @@
const test = require('tape');
const attempt = require('./attempt.js');
test('Testing attempt', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof attempt === 'function', 'attempt is a Function');
t.equals(attempt(() => 0), 0, 'Returns a value');
t.true(attempt(() => {throw new Error()}) instanceof Error, 'Returns an error');
//t.deepEqual(attempt(args..), 'Expected');
//t.equal(attempt(args..), 'Expected');
//t.false(attempt(args..), 'Expected');
//t.throws(attempt(args..), 'Expected');
t.end();
});