Skip to content

Commit 70a0746

Browse files
petehuntzpao
authored andcommitted
Fix react tests
1 parent 1e980a1 commit 70a0746

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

src/core/__tests__/ReactRenderDocument-test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('rendering React components at document', function() {
5858
});
5959

6060
React.renderComponentToString(<Root />, function(markup) {
61-
testDocument.innerHTML = markup;
61+
testDocument = getTestDocument(markup);
6262
var component = React.renderComponent(<Root />, testDocument);
6363
expect(testDocument.body.innerHTML).toBe(' Hello world ');
6464

@@ -86,7 +86,7 @@ describe('rendering React components at document', function() {
8686
});
8787

8888
React.renderComponentToString(<Root />, function(markup) {
89-
testDocument.innerHTML = markup;
89+
testDocument = getTestDocument(markup);
9090
React.renderComponent(<Root />, testDocument);
9191
expect(testDocument.body.innerHTML).toBe(' Hello world ');
9292

@@ -137,7 +137,7 @@ describe('rendering React components at document', function() {
137137
});
138138

139139
React.renderComponentToString(<Component />, function(markup) {
140-
testDocument.innerHTML = markup;
140+
testDocument = getTestDocument(markup);
141141

142142
React.renderComponent(<Component />, testDocument);
143143

@@ -180,7 +180,7 @@ describe('rendering React components at document', function() {
180180
React.renderComponentToString(
181181
<Component text="Hello world" />,
182182
function(markup) {
183-
testDocument.innerHTML = markup;
183+
testDocument = getTestDocument(markup);
184184

185185
React.renderComponent(<Component text="Hello world" />, testDocument);
186186

@@ -210,7 +210,7 @@ describe('rendering React components at document', function() {
210210
React.renderComponentToString(
211211
<Component text="Goodbye world" />,
212212
function(markup) {
213-
testDocument.innerHTML = markup;
213+
testDocument = getTestDocument(markup);
214214

215215
expect(function() {
216216
// Notice the text is different!

src/test/getTestDocument.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
* @providesModule getTestDocument
1717
*/
1818

19-
function getTestDocument() {
19+
function getTestDocument(markup) {
2020
var iframe = document.createElement('iframe');
2121
iframe.style.display = 'none';
2222
document.body.appendChild(iframe);
2323

2424
var testDocument = iframe.contentDocument || iframe.contentWindow.document;
2525
testDocument.open();
26-
testDocument.write('<!doctype html><html><meta charset=utf-8><title>test doc</title>');
26+
testDocument.write(
27+
markup || '<!doctype html><html><meta charset=utf-8><title>test doc</title>'
28+
);
2729
testDocument.close();
2830

2931
iframe.parentNode.removeChild(iframe);

0 commit comments

Comments
 (0)