Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flintinatux committed Sep 17, 2018
1 parent d66d493 commit 3f83307
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ const thrush = curry((x, f) =>
)

// unit :: a -> ()
const unit = Function.prototype
const unit = () => {}

// unless :: (a -> Boolean) -> (a -> a) -> a -> a
const unless = curry((pred, f, x) =>
Expand Down Expand Up @@ -416,6 +416,7 @@ _assign(exports, {
then,
thrush,
unapply,
unit,
unless,
useWith,
values,
Expand Down
20 changes: 20 additions & 0 deletions test/cond.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { expect } = require('chai')

const { cond, constant, prop } = require('..')

describe('cond', () => {
const conditional =
cond([
[ prop('foo'), constant('yes') ],
[ prop('bar'), constant('no') ]
])

it('accepts a list of if/else pred and transformer pairs', () => {
expect(conditional({ foo: true })).to.equal('yes')
expect(conditional({ bar: true })).to.equal('no')
})

it('returns undefined if no preds match', () =>
expect(conditional({ none: true })).to.be.undefined
)
})
22 changes: 22 additions & 0 deletions test/pathEq.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { expect } = require('chai')

const { pathEq } = require('..')

describe('pathEq', () => {
const obj = { foo: { bar: 'yes' } }

it('tests if a nested path is identically equal to a value', () => {
expect(pathEq(['foo', 'bar'], 'yes', obj)).to.be.true
expect(pathEq(['foo', 'bar'], 'no', obj)).to.be.false
})

it('does not fail if the path is missing', () =>
expect(pathEq(['bar', 'foo'], 'yes', obj)).to.be.false
)

it('is curried', () => {
expect(pathEq(['foo', 'bar'])('yes', obj)).to.be.true
expect(pathEq(['foo', 'bar'], 'yes')(obj)).to.be.true
expect(pathEq(['foo', 'bar'])('yes')(obj)).to.be.true
})
})
10 changes: 10 additions & 0 deletions test/unit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { expect } = require('chai')

const { unit } = require('..')

describe('unit', () => {
it('always returns undefined', () => {
expect(unit('a')).to.be.undefined
expect(unit()).to.be.undefined
})
})
2 changes: 1 addition & 1 deletion tinyfunk.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3f83307

Please sign in to comment.