Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
productdevbook committed Nov 16, 2022
1 parent 0482f68 commit 49eee1c
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion test/mergeAndCompare.test.ts
@@ -1,5 +1,5 @@
import { test, expect } from 'vitest'
import { isDate, isString, isArray, isObject } from 'is-what'
import { isDate, isString, isArray } from 'is-what'
import { mergeAndCompare } from '../src/index'

test('conversion based on original val', () => {
Expand Down Expand Up @@ -60,3 +60,57 @@ test('Extend with custom concat arrays', () => {
// const res2 = mergeAndCompare(concatArr, ['a'], ['b'])
// expect(res2).toEqual( ['a', 'b'])
})

test('undefined object', () => {
const origin = {
pages: {
'aa': 'ttt',
},
}

const newData = {
pages: {
'aa': '1111',
'bb': '2222',
}
}

function convertTimestamps(originVal: any, targetVal: any, key: any) {
if (originVal !== undefined)
return targetVal
}

const res = mergeAndCompare(convertTimestamps, origin, newData)
expect(res as any).toEqual({ pages: { aa: "1111", bb: undefined } })
})

test('undefined array', () => {
function convertTimestamps(originVal: any, targetVal: any, key: any) {
if (originVal !== undefined)
return targetVal
}
const origin = {
date: [
{
'new': 'aaa',
}
]
}
const target = {
date: [
{
'new': 'aaa',
'old': 'bbb',
}
]
}
const res = mergeAndCompare(convertTimestamps, origin, target)
expect(res as any).toEqual({
date: [
{
'new': 'aaa',
'old': undefined,
}
]
})
})

0 comments on commit 49eee1c

Please sign in to comment.