2017-04-19 00:55:46 +00:00
|
|
|
import { expect } from 'chai'
|
|
|
|
import u from '../lib'
|
2015-08-05 11:29:30 +00:00
|
|
|
|
|
|
|
describe('u.withDefault', () => {
|
|
|
|
it('uses the default as the basis for the update if the object is undefined', () => {
|
2017-04-19 00:55:46 +00:00
|
|
|
const inc = x => x + 1
|
|
|
|
const result = u.withDefault({ a: 0 }, { a: inc }, undefined)
|
2015-08-05 11:29:30 +00:00
|
|
|
|
2017-04-19 00:55:46 +00:00
|
|
|
expect(result).to.eql({ a: 1 })
|
|
|
|
})
|
2015-08-05 11:29:30 +00:00
|
|
|
|
|
|
|
it('uses ignores the default if the object is defined', () => {
|
2017-04-19 00:55:46 +00:00
|
|
|
const inc = x => x + 1
|
|
|
|
const result = u.withDefault({ a: 0 }, { a: inc }, { a: 3 })
|
2015-08-05 11:29:30 +00:00
|
|
|
|
2017-04-19 00:55:46 +00:00
|
|
|
expect(result).to.eql({ a: 4 })
|
|
|
|
})
|
2015-08-05 11:29:30 +00:00
|
|
|
|
|
|
|
it('can be partially applied', () => {
|
2017-04-19 00:55:46 +00:00
|
|
|
const object = {}
|
|
|
|
const result = u(
|
|
|
|
{
|
|
|
|
foo: u.withDefault([], { 0: 'bar' }),
|
|
|
|
},
|
|
|
|
object
|
|
|
|
)
|
2015-08-05 11:29:30 +00:00
|
|
|
|
2017-04-19 00:55:46 +00:00
|
|
|
expect(result).to.eql({ foo: ['bar'] })
|
|
|
|
})
|
2015-08-05 11:29:30 +00:00
|
|
|
|
|
|
|
it('freezes the result', () => {
|
2017-04-19 00:55:46 +00:00
|
|
|
expect(Object.isFrozen(u.withDefault({}, { a: 1 })(undefined))).to.be.true
|
|
|
|
})
|
|
|
|
})
|