3 changed files with 43 additions and 4 deletions
@ -1,5 +1,31 @@ |
|||||
'use strict'; |
'use strict'; |
||||
|
|
||||
const ReactJSDOM = () => {}; |
const Window = require('window'); |
||||
|
const ReactDOM = require('react-dom'); |
||||
|
|
||||
|
const ReactJSDOM = { |
||||
|
version: ReactDOM.version, |
||||
|
render: component => { |
||||
|
const window = new Window(); |
||||
|
const document = window.document; |
||||
|
|
||||
|
const origGlobals = { |
||||
|
window: global.window, |
||||
|
document: global.document |
||||
|
}; |
||||
|
global.window = window; |
||||
|
global.document = document; |
||||
|
|
||||
|
const container = document.createElement('div'); |
||||
|
ReactDOM.render(component, container); |
||||
|
|
||||
|
Object.keys(origGlobals).forEach(prop => { |
||||
|
global[prop] = origGlobals[prop]; |
||||
|
}); |
||||
|
|
||||
|
return container.children.length > 1 ? container.children : container.children[0]; |
||||
|
} |
||||
|
|
||||
|
}; |
||||
|
|
||||
module.exports = ReactJSDOM; |
module.exports = ReactJSDOM; |
||||
|
@ -1,6 +1,15 @@ |
|||||
import test from 'ava'; |
import test from 'ava'; |
||||
|
import React from 'react'; |
||||
import ReactJSDOM from 'this'; |
import ReactJSDOM from 'this'; |
||||
|
|
||||
test('ReactJSDOM is a function', t => { |
test('ReactJSDOM is a object', t => { |
||||
t.is(typeof ReactJSDOM, 'function'); |
t.is(typeof ReactJSDOM, 'object'); |
||||
|
}); |
||||
|
|
||||
|
test('ReactJSDOM renders a React Component', t => { |
||||
|
const component = ReactJSDOM.render( |
||||
|
React.createElement('div', {}, 'hi') |
||||
|
); |
||||
|
t.is(component.nodeName, 'DIV'); |
||||
|
t.is(component.textContent, 'hi'); |
||||
}); |
}); |
||||
|
Loading…
Reference in new issue