UNPKG

668 BJavaScriptView Raw
1const assert = require('assert');
2const {either} = require('../logic');
3
4describe('Logic', function() {
5 describe('#either()', function() {
6 it('should return the result of function if there is no exception', function(){
7 let fn = either(JSON.parse,0);
8 assert.deepEqual(fn('{"a":3}'),{a:3});
9 });
10 it('should return the default value if there is exception', function(){
11 let fn = either(JSON.parse,0);
12 assert.deepEqual(fn({}),0);
13 });
14 it('should return the default value from a function if there is exception', function(){
15 let fn = either(JSON.parse,x => 0);
16 assert.deepEqual(fn({}),0);
17 });
18 });
19});