Skip to content

Commit

Permalink
test defaultTo
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-king committed Mar 15, 2018
1 parent 90d79a4 commit 0caa93b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 0 additions & 1 deletion test/API.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const args = [null, undefined, false, true, '', 'a', '0xFF', 5, String, /x/, x =

with(R) {

// defaultTo
// head
// is
// last
Expand Down
23 changes: 23 additions & 0 deletions test/defaultTo.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const
{ defaultTo } = require('portable-fp'),
{ testCurrying, varietyList } = require('./util'),
{ expect } = require('chai');

describe('defaultTo :: a → b → a | b', function() {
const
def = 'alternative',
applyDef = v => defaultTo(def, v),
defaults = [null, undefined, NaN],
nonDefaults = varietyList
.filter(x => x !== null && x !== undefined && x === x);

it('replaces null, undefined, and NaN with provided default', function() {
expect(nonDefaults.map(applyDef)).eql(nonDefaults);
expect(defaults.map(applyDef)).eql(defaults.map(x => def));
});

it('has arity of 2', () => expect(defaultTo).lengthOf(2));

it('is curried', testCurrying(defaultTo, [1, NaN], 1));

});
2 changes: 1 addition & 1 deletion test/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('init :: [a] → [a]', function() {
// - expect(init(String)).eql('');

it('returns empty array on (some) invalid defined input', function() {
const args = [true, false, {}, init, x => x, /x/];
const args = [NaN, true, false, {}, init, x => x, /x/];
args.map(arg => expect(init(arg)).an('array').eql([]));
});

Expand Down

0 comments on commit 0caa93b

Please sign in to comment.