Skip to content

Commit

Permalink
fix(path): fix getIn unexpect value with null (#3305)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Aug 2, 2022
1 parent 42fcc28 commit 140aa52
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 6 additions & 0 deletions packages/path/src/__tests__/accessor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { Path } from '../'

const { getIn, setIn } = Path

test('test getIn null parent', () => {
const value = { aa: null }
expect(getIn(value, 'aa')).toEqual(null)
expect(getIn(value, 'aa.bb.cc')).toEqual(undefined)
})

test('test getIn and setIn', () => {
const value = { a: { b: { c: 2, d: 333 } } }
expect(getIn(value, 'a.b.c')).toEqual(2)
Expand Down
7 changes: 1 addition & 6 deletions packages/path/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ const getIn = (segments: Segments, source: any) => {
const index = segments[i]
const rules = getDestructor(index as string)
if (!rules) {
if (!isValid(source)) {
if (i !== segments.length - 1) {
return source
}
break
}
if (!isValid(source)) return
source = source[index]
} else {
source = getInByDestructor(source, rules, { setIn, getIn })
Expand Down
1 change: 0 additions & 1 deletion packages/react/src/__tests__/field.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ test('fields unmount and validate', async () => {
try {
await form.validate()
} catch {}

expect(form.invalid).toBeTruthy()

form.query('parent').take((field) => {
Expand Down

0 comments on commit 140aa52

Please sign in to comment.