add unit test

This commit is contained in:
dntzhang 2018-10-18 17:08:31 +08:00
parent 2fe47b880c
commit 621561e95c
1 changed files with 10 additions and 7 deletions

View File

@ -1,5 +1,6 @@
import { getUpdatePath } from '../src/define'
import { matchGlobalData, needUpdate, fixPath } from '../src/render'
import { npn, nProps } from '../src/util'
//proxy test
//https://github.com/Palindrom/JSONPatcherProxy/blob/master/test/spec/proxySpec.js
@ -16,7 +17,6 @@ test('getUpdatePath', () => {
path = getUpdatePath({ a: 1, b: { c: null } })
expect(path).toEqual({ a: true, 'b.c': true })
path = getUpdatePath({ a: 1, b: { c: [] }, d: {} })
expect(path).toEqual({ a: true, 'b.c': true, d: true })
@ -31,8 +31,6 @@ test('getUpdatePath', () => {
expect(path).toEqual({ a: true, 'b.c[1]': true, 'b.c[0].e': true, d: true })
})
test('matchGlobalData', () => {
expect(matchGlobalData(['a'], { a: 1 })).toEqual(true)
@ -47,8 +45,6 @@ test('matchGlobalData', () => {
})
test('needUpdate', () => {
const path = { 'a': true, 'b.c': true, 'd[2][1]': true }
expect(needUpdate({ a: 1 }, path)).toEqual(true)
@ -67,10 +63,17 @@ test('needUpdate', () => {
})
test('fixPath', () => {
const path = '/a/b/2/d/e'
expect(fixPath(path)).toEqual('a.b[2].d.e')
expect(fixPath('/a/b/1/2/3')).toEqual('a.b[1][2][3]')
})
test('npn', () => {
expect(npn('ab-cd')).toEqual('abCd')
expect(npn('ab-cd-ef')).toEqual('abCdEf')
})
test('nProps', () => {
expect(nProps({ a: { value: 1 }, b: { value: 2 }, abC: { value: 3 } })).toEqual({ a: 1, b: 2, abC: 3 })
})