Added some tests
This commit is contained in:
8
test/attempt/attempt.js
Normal file
8
test/attempt/attempt.js
Normal 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
|
||||
15
test/attempt/attempt.test.js
Normal file
15
test/attempt/attempt.test.js
Normal 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();
|
||||
});
|
||||
Reference in New Issue
Block a user