-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding tests for boolean control #19
Conversation
94065a2
to
b8454a5
Compare
src/antd/Checkbox.tsx
Outdated
@@ -15,7 +15,7 @@ export function Checkbox({ data, className, id, enabled, uischema, schema, path, | |||
return ( | |||
<AntDCheckbox | |||
checked={checked} | |||
onChange={(e: CheckboxChangeEvent) => handleChange(path, e.target.checked)} | |||
onChange={(e: CheckboxChangeEvent) => {handleChange(path, e.target.checked)}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I had added a console log here before. I'll update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
src/controls/BooleanControl.test.tsx
Outdated
const checkbox = await screen.findByLabelText("Name"); | ||
expect(checkbox).not.toBeChecked(); | ||
expect(updateData).not.toHaveBeenCalled(); | ||
|
||
await userEvent.click(checkbox); | ||
expect(checkbox).toBeChecked(); | ||
// FYI the calls to updateData lag behind the actual checkbox state. Not sure why. | ||
// It could be the difference between json-forms handleChange(path, value) and the onChange event. | ||
expect(updateData).toHaveBeenLastCalledWith({ data: {name: false }, errors: []}); | ||
|
||
await userEvent.click(checkbox); | ||
expect(checkbox).not.toBeChecked(); | ||
expect(updateData).toHaveBeenLastCalledWith({ data: {name: true }, errors: []}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DrewHoo i'm seeing this unexpected behavior within my test. Do you know where this could be coming from? I suspect it has something to do with how json form uses handleChange(path, value)
src/antd/Checkbox.tsx
Outdated
@@ -15,7 +15,7 @@ export function Checkbox({ data, className, id, enabled, uischema, schema, path, | |||
return ( | |||
<AntDCheckbox | |||
checked={checked} | |||
onChange={(e: CheckboxChangeEvent) => handleChange(path, e.target.checked)} | |||
onChange={(e: CheckboxChangeEvent) => {handleChange(path, e.target.checked)}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I had added a console log here before. I'll update
5abaac6
to
f0015c0
Compare
No description provided.