Skip to content

Commit

Permalink
fix(@uform/react): Fix Form List error in JSON Schema driver usecase #22
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed May 1, 2019
1 parent 3d43a9a commit 6d11c4b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
45 changes: 45 additions & 0 deletions packages/react/src/__tests__/dynamic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,48 @@ test('dynamic async default value', async () => {
expect(queryAllByTestId('item').length).toBe(1)
expect(queryAllByTestId('input').length).toBe(2)
})

test('invalid schema', async () => {
const TestComponent = () => {
const [schema, setSchema] = useState()
useEffect(() => {
setTimeout(() => {
act(() => {
setSchema({
type: 'object',
properties: {
container: {
type: 'array',
default: [{}],
'x-component': 'container',
properties: {},
items: {
type: 'object',
properties: {
aa: {
type: 'string'
},
bb: {
type: 'string'
}
}
}
}
}
})
})
}, 33)
}, [])
return (
<SchemaForm initialValues={{}} schema={schema}>
<button type='submit'>Submit</button>
</SchemaForm>
)
}
const { queryByText, queryAllByTestId } = render(<TestComponent />)
await sleep(100)
fireEvent.click(queryByText('Add Field'))
await sleep(33)
expect(queryAllByTestId('item').length).toBe(2)
expect(queryAllByTestId('input').length).toBe(4)
})
4 changes: 2 additions & 2 deletions packages/utils/src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export const getSchemaNodeFromPath = (schema, path) => {
path = toArr(path)
for (let i = 0; i < path.length; i++) {
var key = path[i]
if (res && res.properties) {
if (res && !isEmpty(res.properties)) {
res = res.properties[key]
suc++
} else if (res && res.items && numberRE.test(key)) {
} else if (res && !isEmpty(res.items) && numberRE.test(key)) {
res = res.items
suc++
}
Expand Down

0 comments on commit 6d11c4b

Please sign in to comment.