@samitouri / QOS-React-2 / commits / 70a0746e9f

Fix react tests

Pete Hunt committed Jan 6, 2014 at 18:22 UTC 70a0746e9f9877c69edc6a2ef7716c928b71841b
2 files changed +9 -7
src/core/__tests__/ReactRenderDocument-test.js
+5 -5
@@ -58,7 +58,7 @@ describe('rendering React components at document', function() {
58 });
59
60 React.renderComponentToString(<Root />, function(markup) {
61 - testDocument.innerHTML = markup;
61 + testDocument = getTestDocument(markup);
62 var component = React.renderComponent(<Root />, testDocument);
63 expect(testDocument.body.innerHTML).toBe(' Hello world ');
64
@@ -86,7 +86,7 @@ describe('rendering React components at document', function() {
86 });
87
88 React.renderComponentToString(<Root />, function(markup) {
89 - testDocument.innerHTML = markup;
89 + testDocument = getTestDocument(markup);
90 React.renderComponent(<Root />, testDocument);
91 expect(testDocument.body.innerHTML).toBe(' Hello world ');
92
@@ -137,7 +137,7 @@ describe('rendering React components at document', function() {
137 });
138
139 React.renderComponentToString(<Component />, function(markup) {
140 - testDocument.innerHTML = markup;
140 + testDocument = getTestDocument(markup);
141
142 React.renderComponent(<Component />, testDocument);
143
@@ -180,7 +180,7 @@ describe('rendering React components at document', function() {
180 React.renderComponentToString(
181 <Component text="Hello world" />,
182 function(markup) {
183 - testDocument.innerHTML = markup;
183 + testDocument = getTestDocument(markup);
184
185 React.renderComponent(<Component text="Hello world" />, testDocument);
186
@@ -210,7 +210,7 @@ describe('rendering React components at document', function() {
210 React.renderComponentToString(
211 <Component text="Goodbye world" />,
212 function(markup) {
213 - testDocument.innerHTML = markup;
213 + testDocument = getTestDocument(markup);
214
215 expect(function() {
216 // Notice the text is different!
src/test/getTestDocument.js
+4 -2
@@ -16,14 +16,16 @@
16 * @providesModule getTestDocument
17 */
18
19 -function getTestDocument() {
19 +function getTestDocument(markup) {
20 var iframe = document.createElement('iframe');
21 iframe.style.display = 'none';
22 document.body.appendChild(iframe);
23
24 var testDocument = iframe.contentDocument || iframe.contentWindow.document;
25 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 + );
29 testDocument.close();
30
31 iframe.parentNode.removeChild(iframe);