Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
icoloma committed Nov 4, 2020
1 parent fa5b552 commit 29a5270
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/components/InputElements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, {
ChangeEvent,
useEffect,
InputHTMLAttributes,
SyntheticEvent,
} from "react";
import { Converters, Converter } from "../core/Converters";
import { FormContext, FormContextContent } from "./Form";
Expand All @@ -21,7 +20,10 @@ export interface BoundComponentProps
validate?(value: any): Promise<ValidationResult>;

/** onChange event handler has been extended to also receive the formContext */
onChange?(event: SyntheticEvent, formContext: FormContextContent): void;
onChange?(
event: ChangeEvent<HTMLInputElement>,
formContext: FormContextContent
): void;
}

export interface InputProps extends BoundComponentProps {
Expand Down
15 changes: 15 additions & 0 deletions test/InputElementsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,19 @@ describe("Input", function () {
expect(form.toJSON()).toMatchSnapshot();
expect(onSubmit).toHaveBeenCalledTimes(1);
});

it("has access to formContext from onChange", async function () {
mount(
<Input
type="checkbox"
name="foo"
onChange={(e, formContext) => {
const value = e.target.checked;
expect(value).toBe(formContext.getValue("foo"));
}}
/>,
{ foo: true }
);
triggerChange({ value: "xxx", checked: true });
});
});

0 comments on commit 29a5270

Please sign in to comment.