Skip to content

Commit 48742bf

Browse files
sbuschepicfaace
authored andcommitted
Fix file widget tests (rjsf-team#1285)
* react-dom is external peerDependency, just like react. fixes version conflicts, e.g. I got an error Uncaught TypeError: this.updater.enqueueCallback is not a function when using setState callback because I use React 16.x and react-jsonschema-form bundled react-dom 15.x See facebook/react#10320 (comment) * Fix for new submit() method (PR rjsf-team#1058) also submitting the HTML form ..., navigating away from current page at least in Firefox. Reason: dispatched event was not cancelable, so preventDefault in onSubmit couldn't cancel it. Links: * <https://stackoverflow.com/a/40916998> * <https://developer.mozilla.org/en-US/docs/Web/API/Event/cancelable> * Synchronous call to onSubmit() from props Due to the use of setImmediate() hack in setState utility function (utils.js), onSubmit() handler from props is called asynchronously. This leads to massive problems for operations requiring "trusted events", like window.open() or programmatically submitting forms with target "_blank" (which we needed) Because onSubmit() should not need the performance-related setImmiate() hack, I replaced call to setState utility function with proper this.setState() from React. * fix failing FileWidget tests by changing to proper use of setState() without setImmediate() hacks (see rjsf-team#1197) * fix input type, fix test name * Test with newer node versions * Add node 12
1 parent 67d17dd commit 48742bf

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ language:
33
- node_js
44
node_js:
55
- "6"
6+
- "7"
7+
- "8"
8+
- "9"
9+
- "10"
10+
- "11"
11+
- "12"
612
env:
713
- ACTION=test
814
- ACTION="run lint"

src/components/widgets/FileWidget.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from "react";
22
import PropTypes from "prop-types";
33

4-
import { dataURItoBlob, shouldRender, setState } from "../../utils";
4+
import { dataURItoBlob, shouldRender } from "../../utils";
55

66
function addNameToDataURL(dataURL, name) {
77
return dataURL.replace(";base64", `;name=${encodeURIComponent(name)};base64`);
@@ -79,7 +79,7 @@ class FileWidget extends Component {
7979
values: filesInfo.map(fileInfo => fileInfo.dataURL),
8080
filesInfo,
8181
};
82-
setState(this, state, () => {
82+
this.setState(state, () => {
8383
if (multiple) {
8484
onChange(state.values);
8585
} else {

test/StringField_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,7 @@ describe("StringField", () => {
15661566
describe("FileWidget", () => {
15671567
const initialValue = "data:text/plain;name=file1.txt;base64,dGVzdDE=";
15681568

1569-
it("should render a color field", () => {
1569+
it("should render a file field", () => {
15701570
const { node } = createFormComponent({
15711571
schema: {
15721572
type: "string",
@@ -1581,7 +1581,7 @@ describe("StringField", () => {
15811581
const { comp } = createFormComponent({
15821582
schema: {
15831583
type: "string",
1584-
format: "color",
1584+
format: "data-url",
15851585
default: initialValue,
15861586
},
15871587
});

0 commit comments

Comments
 (0)