Skip to content

Commit

Permalink
Test with alternative path
Browse files Browse the repository at this point in the history
  • Loading branch information
kjellmorten committed Sep 17, 2018
1 parent 2ff705e commit 6245b22
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/tests/default-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,45 @@ test('should use default value in array', (t) => {
t.deepEqual(ret, expected)
})

test('should use default value in reverse', (t) => {
const def = {
title: [
'content.heading',
alt(value('Default heading'))
]
}
const data = [
{},
{ title: 'From data' }
]
const expected = [
{ content: { heading: 'Default heading' } },
{ content: { heading: 'From data' } }
]

const ret = mapTransform(def).rev(data)

t.deepEqual(ret, expected)
})

test('should use alternative path', (t) => {
const def = {
title: [ 'heading', alt('headline') ]
}
const data = [
{ heading: 'Entry 1' },
{ headline: 'Entry 2' }
]
const expected = [
{ title: 'Entry 1' },
{ title: 'Entry 2' }
]

const ret = mapTransform(def)(data)

t.deepEqual(ret, expected)
})

test('should set missing values to undefined when no default', (t) => {
const def = {
title: 'content.heading'
Expand Down

0 comments on commit 6245b22

Please sign in to comment.