updeep-remeda/test/withDefault-spec.js

35 lines
857 B
JavaScript
Raw Normal View History

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