Skip to content

Commit 3661616

Browse files
Improve test harness of submit events (facebook#13463)
This PR includes a test that I've enabled in facebook#13358 and another test that we've discussed in facebook#13462 as well as some random cleanup while I'm at it.
1 parent a1be171 commit 3661616

File tree

3 files changed

+210
-147
lines changed

3 files changed

+210
-147
lines changed

fixtures/dom/yarn.lock

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,14 +2153,6 @@ dotenv@4.0.0:
21532153
version "4.0.0"
21542154
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-4.0.0.tgz#864ef1379aced55ce6f95debecdce179f7a0cd1d"
21552155

2156-
draft-js@^0.10.5:
2157-
version "0.10.5"
2158-
resolved "https://registry.yarnpkg.com/draft-js/-/draft-js-0.10.5.tgz#bfa9beb018fe0533dbb08d6675c371a6b08fa742"
2159-
dependencies:
2160-
fbjs "^0.8.15"
2161-
immutable "~3.7.4"
2162-
object-assign "^4.1.0"
2163-
21642156
duplexer2@^0.1.4:
21652157
version "0.1.4"
21662158
resolved "https://registry.yarnpkg.com/duplexer2/-/duplexer2-0.1.4.tgz#8b12dab878c0d69e3e7891051662a32fc6bddcc1"
@@ -2680,7 +2672,7 @@ fbjs@^0.8.1, fbjs@^0.8.4:
26802672
setimmediate "^1.0.5"
26812673
ua-parser-js "^0.7.9"
26822674

2683-
fbjs@^0.8.15, fbjs@^0.8.16:
2675+
fbjs@^0.8.16:
26842676
version "0.8.16"
26852677
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.16.tgz#5e67432f550dc41b572bf55847b8aca64e5337db"
26862678
dependencies:
@@ -3310,10 +3302,6 @@ ignore@^3.3.3:
33103302
version "3.3.3"
33113303
resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.3.tgz#432352e57accd87ab3110e82d3fea0e47812156d"
33123304

3313-
immutable@~3.7.4:
3314-
version "3.7.6"
3315-
resolved "https://registry.yarnpkg.com/immutable/-/immutable-3.7.6.tgz#13b4d3cb12befa15482a26fe1b2ebae640071e4b"
3316-
33173305
imurmurhash@^0.1.4:
33183306
version "0.1.4"
33193307
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"

packages/react-dom/src/__tests__/ReactDOM-test.js

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,41 @@ describe('ReactDOM', () => {
2323
ReactTestUtils = require('react-dom/test-utils');
2424
});
2525

26-
// TODO: uncomment this test once we can run in phantom, which
27-
// supports real submit events.
28-
/*
2926
it('should bubble onSubmit', function() {
30-
const count = 0;
31-
const form;
32-
const Parent = React.createClass({
33-
handleSubmit: function() {
34-
count++;
35-
return false;
36-
},
37-
render: function() {
38-
return <Child />;
39-
}
40-
});
41-
const Child = React.createClass({
42-
render: function() {
43-
return <form><input type="submit" value="Submit" /></form>;
44-
},
45-
componentDidMount: function() {
46-
form = ReactDOM.findDOMNode(this);
47-
}
48-
});
49-
const instance = ReactTestUtils.renderIntoDocument(<Parent />);
50-
form.submit();
51-
expect(count).toEqual(1);
27+
const container = document.createElement('div');
28+
29+
let count = 0;
30+
let buttonRef;
31+
32+
function Parent() {
33+
return (
34+
<div
35+
onSubmit={event => {
36+
event.preventDefault();
37+
count++;
38+
}}>
39+
<Child />
40+
</div>
41+
);
42+
}
43+
44+
function Child() {
45+
return (
46+
<form>
47+
<input type="submit" ref={button => (buttonRef = button)} />
48+
</form>
49+
);
50+
}
51+
52+
document.body.appendChild(container);
53+
try {
54+
ReactDOM.render(<Parent />, container);
55+
buttonRef.click();
56+
expect(count).toBe(1);
57+
} finally {
58+
document.body.removeChild(container);
59+
}
5260
});
53-
*/
5461

5562
it('allows a DOM element to be used with a string', () => {
5663
const element = React.createElement('div', {className: 'foo'});

0 commit comments

Comments
 (0)