Skip to content

Instantly share code, notes, and snippets.

@sirbrillig
Created March 16, 2016 00:02
Show Gist options
  • Save sirbrillig/6314394fdf495c9957a9 to your computer and use it in GitHub Desktop.
Save sirbrillig/6314394fdf495c9957a9 to your computer and use it in GitHub Desktop.
This file should run, but it throws an error
// Set up DOM
var jsdom = require( 'jsdom' ).jsdom;
global.document = jsdom( '' );
global.window = document.defaultView;
global.navigator = document.defaultView.navigator;
// Prepare React
var ReactTestUtils = require( 'react-addons-test-utils' );
var React = require( 'react' );
var Frame = React.createClass( {
componentDidMount() {
console.log( 'iframe loaded. adding content' );
const iframe = this.refs.iframe;
console.log( 'adding content to', iframe.contentWindow ); // Should not be null
iframe.contentWindow.document.open();
iframe.contentWindow.document.write( 'Hello World!' );
iframe.contentWindow.document.close();
},
render() {
console.log( 'rendering iframe' );
return React.createElement( 'iframe', { ref: 'iframe' } );
}
} );
// Render the component
ReactTestUtils.renderIntoDocument( React.createElement( Frame ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment