moy-fp
Version:
A functional programming library.
92 lines (82 loc) • 1.81 kB
JavaScript
import __ from '../../src/Function/__'
/**
* [k] -> {k: v} -> {k: v}
*/
import dissocPath from '../../src/Object/dissocPath'
test('dissocPath(not using __), length 0', () => {
expect(
dissocPath([])({a: 1, b: 2, c: 3})
).toEqual({a: 1, b: 2, c: 3})
})
test('dissocPath(not using __), length 1', () => {
expect(
dissocPath(['a'])({a: 1, b: 2, c: 3})
).toEqual({b: 2, c: 3})
})
test('dissocPath(not using __), length 2, last key is not integer', () => {
expect(
dissocPath(['a', 'x'])({a: {x: 1}, b: 2, c: 3})
).toEqual({a: {}, b: 2, c: 3})
})
test('dissocPath(not using __), length 2, last key is integer', () => {
expect(
dissocPath(['a', 2])({a: [1, 2, 3, 4], b: 2, c: 3})
).toEqual({a: [1, 2, 4], b: 2, c: 3})
})
test('dissocPath(not using __), length 3, without integer', () => {
expect(
dissocPath(['a','x', 'y'])({
a: {x: {y: 1}},
b: 2,
c: 3,
})
).toEqual({
a: {x: {}},
b: 2,
c: 3,
})
})
test('dissocPath(not using __), length 3, with integer', () => {
expect(
dissocPath(['a', 2, 'x'])({
a: [{x: 1}, {x: 2}, {x: 3}],
b: 2,
c: 3,
})
).toEqual({
a: [{x: 1}, {x: 2}, {}],
b: 2,
c: 3,
})
})
test('dissocPath(not using __), length 3, null', () => {
expect(
dissocPath(['a', 2, 'x'])({
a: null,
b: 2,
c: 3,
})
).toEqual({
a: null,
b: 2,
c: 3,
})
})
test('dissocPath(not using __), length 3, undefined', () => {
expect(
dissocPath(['a', 2, 'x'])({
a: [0, 1],
b: 2,
c: 3,
})
).toEqual({
a: [0, 1],
b: 2,
c: 3,
})
})
test('dissocPath(using __), length 2, last key is not integer', () => {
expect(
dissocPath(__, {a: {x: 1}, b: 2, c: 3})(['a', 'x'])
).toEqual({a: {}, b: 2, c: 3})
})