diff --git a/src/Field.test.js b/src/Field.test.js index afd0810..cd2381a 100644 --- a/src/Field.test.js +++ b/src/Field.test.js @@ -1249,3 +1249,91 @@ describe("Field", () => { console.error.mockRestore(); }); }); + +it("should support using format/parse with radio controls", () => { + const format = (value) => value && value.toString(); + const parse = (value) => value && parseInt(value, 10); + + const { getByTestId } = render( +
+ )} + , + ); + expect(getByTestId("ten").checked).toBe(false); + expect(getByTestId("twenty").checked).toBe(true); + expect(getByTestId("thirty").checked).toBe(false); +}); + +it("should support using format/parse with checkbox controls", () => { + const format = (value) => value && value.map((x) => x.toString()); + const parse = (value) => value && value.map((x) => parseInt(x, 10)); + + const { getByTestId } = render( + + )} + , + ); + expect(getByTestId("ten").checked).toBe(false); + expect(getByTestId("twenty").checked).toBe(true); + expect(getByTestId("thirty").checked).toBe(true); +}); diff --git a/src/useField.js b/src/useField.js index c6ffa68..1f3e48c 100644 --- a/src/useField.js +++ b/src/useField.js @@ -161,14 +161,14 @@ function useField