-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@uform/core): fix setFormState Promise resolve is not wait rerend…
…er completed.
- Loading branch information
Showing
4 changed files
with
65 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react' | ||
import SchemaForm, { | ||
Field, | ||
registerFormField, | ||
connect, | ||
createAsyncFormActions | ||
} from '../index' | ||
import { render } from 'react-testing-library' | ||
|
||
beforeEach(() => { | ||
registerFormField('string', connect()(props => <div>{props.value}</div>)) | ||
}) | ||
|
||
test('createFormActions', async () => { | ||
const actions = createAsyncFormActions() | ||
const TestComponent = () => ( | ||
<SchemaForm actions={actions}> | ||
<Field name='aaa' type='string' /> | ||
</SchemaForm> | ||
) | ||
|
||
const { queryByText } = render(<TestComponent />) | ||
await sleep(33) | ||
await actions.setFormState(state => (state.values = { aaa: 123 })) | ||
expect(queryByText('123')).toBeVisible() | ||
await actions.setFieldState('aaa', state => (state.value = 'hello world')) | ||
expect(queryByText('hello world')).toBeVisible() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const defer = () => { | ||
let _resolve | ||
let _reject | ||
const promise = new Promise((resolve, reject) => { | ||
_resolve = resolve | ||
_reject = reject | ||
}) | ||
return { | ||
promise, | ||
resolve: _resolve, | ||
reject: _reject | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters