From eebad166367d85ff61846961a332030c6c81b4f5 Mon Sep 17 00:00:00 2001 From: Thomas Aylott Date: Mon, 25 Nov 2013 15:05:35 -0500 Subject: [PATCH 1/4] =?UTF-8?q?Use=20an=20iframe=20to=20create=20a=20testD?= =?UTF-8?q?ocument=E2=80=A6=20instead=20of=20`createHTMLDocument`=20since?= =?UTF-8?q?=20it=20isn't=20fully=20support=20by=20the=20browsers=20we=20ca?= =?UTF-8?q?re=20about.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes #606 fixes #454 --- src/test/getTestDocument.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/test/getTestDocument.js b/src/test/getTestDocument.js index 9d30b6df57..b0f21ef7cf 100644 --- a/src/test/getTestDocument.js +++ b/src/test/getTestDocument.js @@ -23,11 +23,13 @@ * (jst). */ function getTestDocument() { - if (document.implementation && - document.implementation.createHTMLDocument) { - return document.implementation.createHTMLDocument('test doc'); - } - return null; + var iframe = document.createElement('iframe'); + iframe.style.cssText = 'position:absolute; visibility:hidden; bottom:100%; right:100%'; + iframe.src = 'data:text/html,test doc'; + document.body.appendChild(iframe); + var testDocument = iframe.contentDocument; + iframe.parentNode.removeChild(iframe); + return testDocument; } module.exports = getTestDocument; From 3bfb687de395b3b1dca75539427e54a223541c93 Mon Sep 17 00:00:00 2001 From: Thomas Aylott Date: Mon, 25 Nov 2013 15:08:00 -0500 Subject: [PATCH 2/4] remove warning comment about `createHTMLDocument` --- src/test/getTestDocument.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/test/getTestDocument.js b/src/test/getTestDocument.js index b0f21ef7cf..794d5c33e6 100644 --- a/src/test/getTestDocument.js +++ b/src/test/getTestDocument.js @@ -16,12 +16,6 @@ * @providesModule getTestDocument */ -/** - * We need to work around the fact that we have two different - * test implementations: once that breaks if we clobber document - * (open-source) and one that doesn't support createHTMLDocument() - * (jst). - */ function getTestDocument() { var iframe = document.createElement('iframe'); iframe.style.cssText = 'position:absolute; visibility:hidden; bottom:100%; right:100%'; From f4753030a2890db116478c2983655b873d709d75 Mon Sep 17 00:00:00 2001 From: Thomas Aylott Date: Mon, 25 Nov 2013 16:01:05 -0500 Subject: [PATCH 3/4] IE support --- src/test/getTestDocument.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/test/getTestDocument.js b/src/test/getTestDocument.js index 794d5c33e6..c8ce52ffc9 100644 --- a/src/test/getTestDocument.js +++ b/src/test/getTestDocument.js @@ -18,10 +18,14 @@ function getTestDocument() { var iframe = document.createElement('iframe'); - iframe.style.cssText = 'position:absolute; visibility:hidden; bottom:100%; right:100%'; - iframe.src = 'data:text/html,test doc'; + iframe.style.display = 'none'; document.body.appendChild(iframe); - var testDocument = iframe.contentDocument; + + var testDocument = iframe.contentDocument || iframe.contentWindow.document; + testDocument.open(); + testDocument.write('test doc'); + testDocument.close(); + iframe.parentNode.removeChild(iframe); return testDocument; } From 916ee6b3946dc2e79a7a1f932272c31d6936bf9f Mon Sep 17 00:00:00 2001 From: Thomas Aylott Date: Wed, 27 Nov 2013 17:00:01 -0500 Subject: [PATCH 4/4] jsx & JSDOM support --- .../__tests__/ReactRenderDocument-test.js | 35 ++++--------------- src/test/getTestDocument.js | 2 +- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/src/core/__tests__/ReactRenderDocument-test.js b/src/core/__tests__/ReactRenderDocument-test.js index dd5250811c..4ecff37d76 100644 --- a/src/core/__tests__/ReactRenderDocument-test.js +++ b/src/core/__tests__/ReactRenderDocument-test.js @@ -40,10 +40,7 @@ describe('rendering React components at document', function() { }); it('should be able to get root component id for document node', function() { - if (!testDocument) { - // These tests are not applicable in jst, since jsdom is buggy. - return; - } + expect(testDocument).not.toBeUndefined(); var Root = React.createClass({ render: function() { @@ -69,10 +66,7 @@ describe('rendering React components at document', function() { }); it('should be able to unmount component from document node', function() { - if (!testDocument) { - // These tests are not applicable in jst, since jsdom is buggy. - return; - } + expect(testDocument).not.toBeUndefined(); var Root = React.createClass({ render: function() { @@ -100,10 +94,7 @@ describe('rendering React components at document', function() { }); it('should be able to switch root constructors via state', function() { - if (!testDocument) { - // These tests are not applicable in jst, since jsdom is buggy. - return; - } + expect(testDocument).not.toBeUndefined(); var Component = React.createClass({ render: function() { @@ -162,10 +153,7 @@ describe('rendering React components at document', function() { }); it('should be able to switch root constructors', function() { - if (!testDocument) { - // These tests are not applicable in jst, since jsdom is buggy. - return; - } + expect(testDocument).not.toBeUndefined(); var Component = React.createClass({ render: function() { @@ -210,10 +198,7 @@ describe('rendering React components at document', function() { }); it('should be able to mount into document', function() { - if (!testDocument) { - // These tests are not applicable in jst, since jsdom is buggy. - return; - } + expect(testDocument).not.toBeUndefined(); var Component = React.createClass({ render: function() { @@ -236,10 +221,7 @@ describe('rendering React components at document', function() { }); it('should throw on full document render', function() { - if (!testDocument) { - // These tests are not applicable in jst, since jsdom is buggy. - return; - } + expect(testDocument).not.toBeUndefined(); var container = testDocument; expect(function() { @@ -255,10 +237,7 @@ describe('rendering React components at document', function() { }); it('should throw on full document render of non-html', function() { - if (!testDocument) { - // These tests are not applicable in jst, since jsdom is buggy. - return; - } + expect(testDocument).not.toBeUndefined(); var container = testDocument; ReactMount.allowFullPageRender = true; diff --git a/src/test/getTestDocument.js b/src/test/getTestDocument.js index c8ce52ffc9..82d7d64dfb 100644 --- a/src/test/getTestDocument.js +++ b/src/test/getTestDocument.js @@ -23,7 +23,7 @@ function getTestDocument() { var testDocument = iframe.contentDocument || iframe.contentWindow.document; testDocument.open(); - testDocument.write('test doc'); + testDocument.write('test doc'); testDocument.close(); iframe.parentNode.removeChild(iframe);