Skip to content

Commit

Permalink
React -> ReactDOM in test files
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiebits committed Sep 1, 2015
1 parent 31cb102 commit b1e16b9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ of patent rights can be found in the PATENTS file in the same directory.
###

React = null
ReactDOM = null

describe 'ReactCoffeeScriptClass', ->
div = null
Expand All @@ -19,6 +20,7 @@ describe 'ReactCoffeeScriptClass', ->

beforeEach ->
React = require 'React'
ReactDOM = require 'ReactDOM'
container = document.createElement 'div'
attachedListener = null
renderedName = null
Expand All @@ -33,7 +35,7 @@ describe 'ReactCoffeeScriptClass', ->
Inner = React.createFactory InnerComponent

test = (element, expectedTag, expectedClassName) ->
instance = React.render(element, container)
instance = ReactDOM.render(element, container)
expect(container.firstChild).not.toBeNull()
expect(container.firstChild.tagName).toBe(expectedTag)
expect(container.firstChild.className).toBe(expectedClassName)
Expand All @@ -47,7 +49,7 @@ describe 'ReactCoffeeScriptClass', ->
spyOn console, 'error'
class Foo extends React.Component
expect(->
React.render React.createElement(Foo), container
ReactDOM.render React.createElement(Foo), container
).toThrow()
expect(console.error.calls.length).toBe(1)
expect(console.error.calls[0].args[0]).toContain('No `render` method found on the returned component instance')
Expand Down Expand Up @@ -262,7 +264,7 @@ describe 'ReactCoffeeScriptClass', ->
'did-update', { value: 'foo' }, {}
]
lifeCycles = [] # reset
React.unmountComponentAtNode container
ReactDOM.unmountComponentAtNode container
expect(lifeCycles).toEqual ['will-unmount']

it 'warns when classic properties are defined on the instance,
Expand Down Expand Up @@ -394,5 +396,5 @@ describe 'ReactCoffeeScriptClass', ->

it 'supports drilling through to the DOM using findDOMNode', ->
instance = test Inner(name: 'foo'), 'DIV', 'foo'
node = React.findDOMNode(instance)
node = ReactDOM.findDOMNode(instance)
expect(node).toBe container.firstChild
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ describe('ReactDOMComponent', function() {
});

expect(function() {
React.render(<Animal/>, container);
ReactDOM.render(<Animal/>, container);
}).toThrow(
'Invariant Violation: The `style` prop expects a mapping from style ' +
'properties to values, not a string. For example, ' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'use strict';

var React;
var ReactDOM;
var ReactTestUtils;

function StatelessComponent(props) {
Expand All @@ -22,12 +23,13 @@ describe('ReactStatelessComponent', function() {

beforeEach(function() {
React = require('React');
ReactDOM = require('ReactDOM');
ReactTestUtils = require('ReactTestUtils');
});

it('should render stateless component', function() {
var el = document.createElement('div');
React.render(<StatelessComponent name="A" />, el);
ReactDOM.render(<StatelessComponent name="A" />, el);

expect(el.textContent).toBe('A');
});
Expand All @@ -40,20 +42,20 @@ describe('ReactStatelessComponent', function() {
});

var el = document.createElement('div');
React.render(<Parent name="A" />, el);
ReactDOM.render(<Parent name="A" />, el);
expect(el.textContent).toBe('A');

React.render(<Parent name="B" />, el);
ReactDOM.render(<Parent name="B" />, el);
expect(el.textContent).toBe('B');
});

it('should unmount stateless component', function() {
var container = document.createElement('div');

React.render(<StatelessComponent name="A" />, container);
ReactDOM.render(<StatelessComponent name="A" />, container);
expect(container.textContent).toBe('A');

React.unmountComponentAtNode(container);
ReactDOM.unmountComponentAtNode(container);
expect(container.textContent).toBe('');
});

Expand Down Expand Up @@ -87,11 +89,11 @@ describe('ReactStatelessComponent', function() {
});

var el = document.createElement('div');
React.render(<GrandParent test="test" />, el);
ReactDOM.render(<GrandParent test="test" />, el);

expect(el.textContent).toBe('test');

React.render(<GrandParent test="mest" />, el);
ReactDOM.render(<GrandParent test="mest" />, el);

expect(el.textContent).toBe('mest');
});
Expand All @@ -106,7 +108,7 @@ describe('ReactStatelessComponent', function() {
}

var el = document.createElement('div');
React.render(<Child test="test" />, el);
ReactDOM.render(<Child test="test" />, el);

expect(el.textContent).toBe('test');
});
Expand Down Expand Up @@ -178,7 +180,7 @@ describe('ReactStatelessComponent', function() {
Child.contextTypes = {lang: React.PropTypes.string};

var el = document.createElement('div');
React.render(<Parent />, el);
ReactDOM.render(<Parent />, el);
expect(el.textContent).toBe('en');
});
});
8 changes: 4 additions & 4 deletions src/test/__tests__/ReactTestUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,9 @@ describe('ReactTestUtils', function() {
it('should change the value of an input field', function() {
var handler = jasmine.createSpy('spy');
var container = document.createElement('div');
var instance = React.render(<input type="text" onChange={handler} />, container);
var instance = ReactDOM.render(<input type="text" onChange={handler} />, container);

var node = React.findDOMNode(instance);
var node = ReactDOM.findDOMNode(instance);
node.value = 'giraffe';
ReactTestUtils.Simulate.change(node);

Expand All @@ -360,9 +360,9 @@ describe('ReactTestUtils', function() {

var handler = jasmine.createSpy('spy');
var container = document.createElement('div');
var instance = React.render(<SomeComponent handleChange={handler} />, container);
var instance = ReactDOM.render(<SomeComponent handleChange={handler} />, container);

var node = React.findDOMNode(instance.refs.input);
var node = ReactDOM.findDOMNode(instance.refs.input);
node.value = 'zebra';
ReactTestUtils.Simulate.change(node);

Expand Down

0 comments on commit b1e16b9

Please sign in to comment.