|
1 | 1 | import { expect } from "chai";
|
2 | 2 | import sinon from "sinon";
|
3 | 3 | import React from "react";
|
4 |
| -import { renderIntoDocument, Simulate } from "react-dom/test-utils"; |
| 4 | +import { renderIntoDocument, act, Simulate } from "react-dom/test-utils"; |
5 | 5 | import { findDOMNode } from "react-dom";
|
6 | 6 | import { Portal } from "react-portal";
|
7 | 7 | import { createRef } from "create-react-ref";
|
@@ -871,7 +871,55 @@ describeRepeated("Form common", createFormComponent => {
|
871 | 871 | },
|
872 | 872 | });
|
873 | 873 | });
|
| 874 | + |
| 875 | + it("should call last provided change handler", async () => { |
| 876 | + const schema = { |
| 877 | + type: "object", |
| 878 | + properties: { |
| 879 | + foo: { |
| 880 | + type: "string", |
| 881 | + default: "bar", |
| 882 | + }, |
| 883 | + }, |
| 884 | + }; |
| 885 | + |
| 886 | + const secondOnChange = sandbox.spy(); |
| 887 | + |
| 888 | + const { comp, onChange } = createFormComponent({ |
| 889 | + schema, |
| 890 | + formData: { foo: "bar1" }, |
| 891 | + }); |
| 892 | + |
| 893 | + act(() => { |
| 894 | + setProps(comp, { |
| 895 | + schema, |
| 896 | + formData: {}, |
| 897 | + onChange, |
| 898 | + }); |
| 899 | + }); |
| 900 | + |
| 901 | + sinon.assert.callCount(onChange, 1); |
| 902 | + |
| 903 | + act(() => { |
| 904 | + setProps(comp, { |
| 905 | + schema, |
| 906 | + formData: { foo: "bar2" }, |
| 907 | + }); |
| 908 | + }); |
| 909 | + |
| 910 | + act(() => { |
| 911 | + setProps(comp, { |
| 912 | + schema, |
| 913 | + formData: {}, |
| 914 | + onChange: secondOnChange, |
| 915 | + }); |
| 916 | + }); |
| 917 | + |
| 918 | + sinon.assert.callCount(onChange, 1); |
| 919 | + sinon.assert.callCount(secondOnChange, 1); |
| 920 | + }); |
874 | 921 | });
|
| 922 | + |
875 | 923 | describe("Blur handler", () => {
|
876 | 924 | it("should call provided blur handler on form input blur event", () => {
|
877 | 925 | const schema = {
|
|
0 commit comments