Skip to main content
Module

x/rambda/cond.spec.js

Faster and smaller alternative to Ramda
Go to Latest
File
import { always } from './always'import { cond } from './cond'import { equals } from './equals'import { T } from './T'
test('returns a function', () => { expect(typeof cond([])).toEqual('function')})
test('returns a conditional function', () => { const fn = cond([ [ equals(0), always('water freezes at 0°C') ], [ equals(100), always('water boils at 100°C') ], [ T, function (temp){ return 'nothing special happens at ' + temp + '°C' }, ], ]) expect(fn(0)).toEqual('water freezes at 0°C') expect(fn(50)).toEqual('nothing special happens at 50°C') expect(fn(100)).toEqual('water boils at 100°C')})
test('no winner', () => { const fn = cond([ [ equals('foo'), always(1) ], [ equals('bar'), always(2) ], ]) expect(fn('quux')).toEqual(undefined)})
test('predicates are tested in order', () => { const fn = cond([ [ T, always('foo') ], [ T, always('bar') ], [ T, always('baz') ], ]) expect(fn()).toEqual('foo')})