Fix some invalid uses of instances

Breaking this out of the other code mod.
This commit is contained in:
Sebastian Markbage
2014-03-13 16:23:47 -07:00
committed by Paul O’Shannessy
parent 7bbdcdba96
commit 9b427a322f
7 changed files with 138 additions and 124 deletions
+2 -1
View File
@@ -75,7 +75,8 @@ function renderComponentToStaticMarkup(component) {
transaction = ReactServerRenderingTransaction.getPooled(true);
return transaction.perform(function() {
return component.mountComponent(id, transaction, 0);
var componentInstance = instantiateReactComponent(component);
return componentInstance.mountComponent(id, transaction, 0);
}, null);
} finally {
ReactServerRenderingTransaction.release(transaction);
@@ -29,37 +29,32 @@ describe('ReactDOMInput', function() {
var ReactLink;
var ReactTestUtils;
var renderTextInput;
beforeEach(function() {
React = require('React');
ReactLink = require('ReactLink');
ReactTestUtils = require('ReactTestUtils');
renderTextInput = function(component) {
var stub = ReactTestUtils.renderIntoDocument(component);
var node = stub.getDOMNode();
return node;
};
});
it('should display `defaultValue` of number 0', function() {
var stub = <input type="text" defaultValue={0} />;
var node = renderTextInput(stub);
stub = ReactTestUtils.renderIntoDocument(stub);
var node = stub.getDOMNode();
expect(node.value).toBe('0');
});
it('should display "true" for `defaultValue` of `true`', function() {
var stub = <input type="text" defaultValue={true} />;
var node = renderTextInput(stub);
stub = ReactTestUtils.renderIntoDocument(stub);
var node = stub.getDOMNode();
expect(node.value).toBe('true');
});
it('should display "false" for `defaultValue` of `false`', function() {
var stub = <input type="text" defaultValue={false} />;
var node = renderTextInput(stub);
stub = ReactTestUtils.renderIntoDocument(stub);
var node = stub.getDOMNode();
expect(node.value).toBe('false');
});
@@ -72,21 +67,24 @@ describe('ReactDOMInput', function() {
};
var stub = <input type="text" defaultValue={objToString} />;
var node = renderTextInput(stub);
stub = ReactTestUtils.renderIntoDocument(stub);
var node = stub.getDOMNode();
expect(node.value).toBe('foobar');
});
it('should display `value` of number 0', function() {
var stub = <input type="text" value={0} />;
var node = renderTextInput(stub);
stub = ReactTestUtils.renderIntoDocument(stub);
var node = stub.getDOMNode();
expect(node.value).toBe('0');
});
it('should allow setting `value` to `true`', function() {
var stub = <input type="text" value="yolo" />;
var node = renderTextInput(stub);
stub = ReactTestUtils.renderIntoDocument(stub);
var node = stub.getDOMNode();
expect(node.value).toBe('yolo');
@@ -96,7 +94,8 @@ describe('ReactDOMInput', function() {
it("should allow setting `value` to `false`", function() {
var stub = <input type="text" value="yolo" />;
var node = renderTextInput(stub);
stub = ReactTestUtils.renderIntoDocument(stub);
var node = stub.getDOMNode();
expect(node.value).toBe('yolo');
@@ -106,7 +105,8 @@ describe('ReactDOMInput', function() {
it('should allow setting `value` to `objToString`', function() {
var stub = <input type="text" value="foo" />;
var node = renderTextInput(stub);
stub = ReactTestUtils.renderIntoDocument(stub);
var node = stub.getDOMNode();
expect(node.value).toBe('foo');
@@ -122,7 +122,8 @@ describe('ReactDOMInput', function() {
it('should properly control a value of number `0`', function() {
var stub = <input type="text" value={0} />;
var node = renderTextInput(stub);
stub = ReactTestUtils.renderIntoDocument(stub);
var node = stub.getDOMNode();
node.value = 'giraffe';
ReactTestUtils.Simulate.change(node);
@@ -131,7 +132,8 @@ describe('ReactDOMInput', function() {
it('should not set a value for submit buttons unnecessarily', function() {
var stub = <input type="submit" />;
var node = renderTextInput(stub);
stub = ReactTestUtils.renderIntoDocument(stub);
var node = stub.getDOMNode();
// The value shouldn't be '', or else the button will have no text; it
// should have the default "Submit" or "Submit Query" label
@@ -184,7 +186,7 @@ describe('ReactDOMInput', function() {
var link = new ReactLink('yolo', mocks.getMockFunction());
var instance = <input type="text" valueLink={link} />;
React.renderComponent(instance, container);
instance = React.renderComponent(instance, container);
expect(instance.getDOMNode().value).toBe('yolo');
expect(link.value).toBe('yolo');
@@ -257,7 +259,7 @@ describe('ReactDOMInput', function() {
var link = new ReactLink(true, mocks.getMockFunction());
var instance = <input type="checkbox" checkedLink={link} />;
React.renderComponent(instance, container);
instance = React.renderComponent(instance, container);
expect(instance.getDOMNode().checked).toBe(true);
expect(link.value).toBe(true);
@@ -28,18 +28,10 @@ describe('ReactDOMSelect', function() {
var ReactLink;
var ReactTestUtils;
var renderSelect;
beforeEach(function() {
React = require('React');
ReactLink = require('ReactLink');
ReactTestUtils = require('ReactTestUtils');
renderSelect = function(component) {
var stub = ReactTestUtils.renderIntoDocument(component);
var node = stub.getDOMNode();
return node;
};
});
it('should allow setting `defaultValue`', function() {
@@ -49,7 +41,8 @@ describe('ReactDOMSelect', function() {
<option value="giraffe">A giraffe!</option>
<option value="gorilla">A gorilla!</option>
</select>;
var node = renderSelect(stub);
stub = ReactTestUtils.renderIntoDocument(stub);
var node = stub.getDOMNode();
expect(node.value).toBe('giraffe');
@@ -65,7 +58,8 @@ describe('ReactDOMSelect', function() {
<option value="giraffe">A giraffe!</option>
<option value="gorilla">A gorilla!</option>
</select>;
var node = renderSelect(stub);
stub = ReactTestUtils.renderIntoDocument(stub);
var node = stub.getDOMNode();
expect(node.value).toBe('giraffe');
@@ -82,7 +76,8 @@ describe('ReactDOMSelect', function() {
<option value="giraffe">A giraffe!</option>
<option value="gorilla">A gorilla!</option>
</select>;
var node = renderSelect(stub);
stub = ReactTestUtils.renderIntoDocument(stub);
var node = stub.getDOMNode();
expect(node.options[0].selected).toBe(false); // monkey
expect(node.options[1].selected).toBe(true); // giraffe
@@ -103,7 +98,8 @@ describe('ReactDOMSelect', function() {
<option value="giraffe">A giraffe!</option>
<option value="gorilla">A gorilla!</option>
</select>;
var node = renderSelect(stub);
stub = ReactTestUtils.renderIntoDocument(stub);
var node = stub.getDOMNode();
expect(node.value).toBe('giraffe');
@@ -119,7 +115,8 @@ describe('ReactDOMSelect', function() {
<option value="giraffe">A giraffe!</option>
<option value="gorilla">A gorilla!</option>
</select>;
var node = renderSelect(stub);
stub = ReactTestUtils.renderIntoDocument(stub);
var node = stub.getDOMNode();
expect(node.options[0].selected).toBe(false); // monkey
expect(node.options[1].selected).toBe(true); // giraffe
@@ -140,7 +137,8 @@ describe('ReactDOMSelect', function() {
<option value="2">two</option>
<option value="12">twelve</option>
</select>;
var node = renderSelect(stub);
stub = ReactTestUtils.renderIntoDocument(stub);
var node = stub.getDOMNode();
expect(node.options[0].selected).toBe(false); // one
expect(node.options[1].selected).toBe(false); // two
@@ -161,7 +159,8 @@ describe('ReactDOMSelect', function() {
<option value="giraffe">A giraffe!</option>
<option value="gorilla">A gorilla!</option>
</select>;
var node = renderSelect(stub);
stub = ReactTestUtils.renderIntoDocument(stub);
var node = stub.getDOMNode();
expect(node.options[0].selected).toBe(false); // monkey
expect(node.options[1].selected).toBe(true); // giraffe
@@ -183,7 +182,8 @@ describe('ReactDOMSelect', function() {
<option value="giraffe">A giraffe!</option>
<option value="gorilla">A gorilla!</option>
</select>;
var node = renderSelect(stub);
stub = ReactTestUtils.renderIntoDocument(stub);
var node = stub.getDOMNode();
expect(node.options[0].selected).toBe(false); // monkey
expect(node.options[1].selected).toBe(true); // giraffe
@@ -204,7 +204,8 @@ describe('ReactDOMSelect', function() {
<option value="giraffe">A giraffe!</option>
<option value="gorilla">A gorilla!</option>
</select>;
var node = renderSelect(stub);
stub = ReactTestUtils.renderIntoDocument(stub);
var node = stub.getDOMNode();
expect(node.options[0].selected).toBe(false); // monkey
expect(node.options[1].selected).toBe(true); // giraffe
@@ -227,7 +228,8 @@ describe('ReactDOMSelect', function() {
<option value="giraffe">A giraffe!</option>
<option value="gorilla">A gorilla!</option>
</select>;
var node = renderSelect(stub);
stub = ReactTestUtils.renderIntoDocument(stub);
var node = stub.getDOMNode();
expect(node.options[0].selected).toBe(false); // monkey
expect(node.options[1].selected).toBe(true); // giraffe
@@ -40,13 +40,14 @@ describe('ReactDOMTextarea', function() {
var node = stub.getDOMNode();
// Polyfilling the browser's quirky behavior.
node.value = node.innerHTML;
return node;
return stub;
};
});
it('should allow setting `defaultValue`', function() {
var stub = <textarea defaultValue="giraffe" />;
var node = renderTextarea(stub);
stub = renderTextarea(stub);
var node = stub.getDOMNode();
expect(node.value).toBe('giraffe');
@@ -57,14 +58,16 @@ describe('ReactDOMTextarea', function() {
it('should display `defaultValue` of number 0', function() {
var stub = <textarea defaultValue={0} />;
var node = renderTextarea(stub);
stub = renderTextarea(stub);
var node = stub.getDOMNode();
expect(node.value).toBe('0');
});
it('should display "false" for `defaultValue` of `false`', function() {
var stub = <textarea type="text" defaultValue={false} />;
var node = renderTextarea(stub);
stub = renderTextarea(stub);
var node = stub.getDOMNode();
expect(node.value).toBe('false');
});
@@ -77,21 +80,24 @@ describe('ReactDOMTextarea', function() {
};
var stub = <textarea type="text" defaultValue={objToString} />;
var node = renderTextarea(stub);
stub = renderTextarea(stub);
var node = stub.getDOMNode();
expect(node.value).toBe('foobar');
});
it('should display `value` of number 0', function() {
var stub = <textarea value={0} />;
var node = renderTextarea(stub);
stub = renderTextarea(stub);
var node = stub.getDOMNode();
expect(node.value).toBe('0');
});
it('should allow setting `value` to `giraffe`', function() {
var stub = <textarea value="giraffe" />;
var node = renderTextarea(stub);
stub = renderTextarea(stub);
var node = stub.getDOMNode();
expect(node.value).toBe('giraffe');
@@ -101,7 +107,8 @@ describe('ReactDOMTextarea', function() {
it('should allow setting `value` to `true`', function() {
var stub = <textarea value="giraffe" />;
var node = renderTextarea(stub);
stub = renderTextarea(stub);
var node = stub.getDOMNode();
expect(node.value).toBe('giraffe');
@@ -111,7 +118,8 @@ describe('ReactDOMTextarea', function() {
it('should allow setting `value` to `false`', function() {
var stub = <textarea value="giraffe" />;
var node = renderTextarea(stub);
stub = renderTextarea(stub);
var node = stub.getDOMNode();
expect(node.value).toBe('giraffe');
@@ -121,7 +129,8 @@ describe('ReactDOMTextarea', function() {
it('should allow setting `value` to `objToString`', function() {
var stub = <textarea value="giraffe" />;
var node = renderTextarea(stub);
stub = renderTextarea(stub);
var node = stub.getDOMNode();
expect(node.value).toBe('giraffe');
@@ -136,7 +145,8 @@ describe('ReactDOMTextarea', function() {
it('should properly control a value of number `0`', function() {
var stub = <textarea value={0} />;
var node = renderTextarea(stub);
stub = renderTextarea(stub);
var node = stub.getDOMNode();
node.value = 'giraffe';
ReactTestUtils.Simulate.change(node);
@@ -147,7 +157,8 @@ describe('ReactDOMTextarea', function() {
spyOn(console, 'warn');
var stub = <textarea>giraffe</textarea>;
var node = renderTextarea(stub);
stub = renderTextarea(stub);
var node = stub.getDOMNode();
expect(console.warn.argsForCall.length).toBe(1);
expect(node.value).toBe('giraffe');
@@ -159,14 +170,14 @@ describe('ReactDOMTextarea', function() {
it('should allow numbers as children', function() {
spyOn(console, 'warn');
var node = renderTextarea(<textarea>{17}</textarea>);
var node = renderTextarea(<textarea>{17}</textarea>).getDOMNode();
expect(console.warn.argsForCall.length).toBe(1);
expect(node.value).toBe('17');
});
it('should allow booleans as children', function() {
spyOn(console, 'warn');
var node = renderTextarea(<textarea>{false}</textarea>);
var node = renderTextarea(<textarea>{false}</textarea>).getDOMNode();
expect(console.warn.argsForCall.length).toBe(1);
expect(node.value).toBe('false');
});
@@ -178,7 +189,7 @@ describe('ReactDOMTextarea', function() {
return "sharkswithlasers";
}
};
var node = renderTextarea(<textarea>{obj}</textarea>);
var node = renderTextarea(<textarea>{obj}</textarea>).getDOMNode();
expect(console.warn.argsForCall.length).toBe(1);
expect(node.value).toBe('sharkswithlasers');
});
@@ -194,12 +205,12 @@ describe('ReactDOMTextarea', function() {
expect(console.warn.argsForCall.length).toBe(1);
var stub;
var node;
expect(function() {
stub = renderTextarea(<textarea><strong /></textarea>);
node = renderTextarea(<textarea><strong /></textarea>).getDOMNode();
}).not.toThrow();
expect(stub.value).toBe('[object Object]');
expect(node.value).toBe('[object Object]');
expect(console.warn.argsForCall.length).toBe(2);
});
@@ -209,7 +220,7 @@ describe('ReactDOMTextarea', function() {
var link = new ReactLink('yolo', mocks.getMockFunction());
var instance = <textarea valueLink={link} />;
React.renderComponent(instance, container);
instance = React.renderComponent(instance, container);
expect(instance.getDOMNode().value).toBe('yolo');
expect(link.value).toBe('yolo');
+3 -3
View File
@@ -62,13 +62,13 @@ describe('autobinding', function() {
var instance1 = <TestBindComponent />;
var mountedInstance1 = ReactTestUtils.renderIntoDocument(instance1);
var rendered1 = reactComponentExpect(instance1)
var rendered1 = reactComponentExpect(mountedInstance1)
.expectRenderedChild()
.instance();
var instance2 = <TestBindComponent />;
var mountedInstance2 = ReactTestUtils.renderIntoDocument(instance2);
var rendered2 = reactComponentExpect(instance2)
var rendered2 = reactComponentExpect(mountedInstance2)
.expectRenderedChild()
.instance();
@@ -123,7 +123,7 @@ describe('autobinding', function() {
var instance1 = <TestBindComponent />;
var mountedInstance1 = ReactTestUtils.renderIntoDocument(instance1);
var rendered1 = reactComponentExpect(instance1)
var rendered1 = reactComponentExpect(mountedInstance1)
.expectRenderedChild()
.instance();
@@ -108,11 +108,11 @@ describe('ReactComponentLifeCycle', function() {
}
});
var instance = <StatefulComponent />;
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
instance.addAnotherField();
expect(instance.state.aField).toBe('asdf');
instance.unmountComponent();
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
expect(typeof instance.state.aField).toBe('undefined');
});
@@ -157,7 +157,7 @@ describe('ReactComponentLifeCycle', function() {
});
var instance = <SwitcherParent />;
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
expect(_testJournal).toEqual([
'SwitcherParent:getInitialState',
'SwitcherParent:onDOMReady',
@@ -180,11 +180,11 @@ describe('ReactComponentLifeCycle', function() {
}
});
var instance = <StatefulComponent />;
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
instance.addAnotherField();
expect(instance.state.aField).toBe('asdf');
instance.unmountComponent();
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
expect(instance.state).toBe(null);
});
@@ -203,7 +203,7 @@ describe('ReactComponentLifeCycle', function() {
});
var instance = <StatefulComponent />;
expect(function() {
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
}).toThrow();
});
@@ -220,7 +220,7 @@ describe('ReactComponentLifeCycle', function() {
});
var instance = <StatefulComponent />;
expect(function() {
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
}).not.toThrow();
});
@@ -239,7 +239,7 @@ describe('ReactComponentLifeCycle', function() {
});
var instance = <StatefulComponent />;
expect(function() {
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
}).not.toThrow();
// The return value of getInitialState overrides anything from setState
@@ -403,7 +403,7 @@ describe('ReactComponentLifeCycle', function() {
valueToUseInOnDOMReady="goodbye"
/>;
expect(function() {
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
}).toThrow(
'Invariant Violation: replaceProps(...): You called `setProps` or ' +
'`replaceProps` on a component with a parent. This is an anti-pattern ' +
@@ -497,7 +497,7 @@ describe('ReactComponentLifeCycle', function() {
valueToUseInitially="hello"
valueToUseInOnDOMReady="goodbye"
/>;
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
expect(instance.state.stateField).toBe('goodbye');
});
@@ -92,7 +92,7 @@ describe('ReactCompositeComponent', function() {
it('should support rendering to different child types over time', function() {
var instance = <MorphingComponent />;
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
reactComponentExpect(instance)
.expectRenderedChild()
@@ -111,7 +111,7 @@ describe('ReactCompositeComponent', function() {
it('should react to state changes from callbacks', function() {
var instance = <MorphingComponent />;
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
var renderedChild = reactComponentExpect(instance)
.expectRenderedChild()
@@ -125,7 +125,7 @@ describe('ReactCompositeComponent', function() {
it('should rewire refs when rendering to different child types', function() {
var instance = <MorphingComponent />;
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
reactComponentExpect(instance.refs.x).toBeDOMComponentWithTag('a');
instance._toggleActivatedState();
@@ -136,7 +136,7 @@ describe('ReactCompositeComponent', function() {
it('should not cache old DOM nodes when switching constructors', function() {
var instance = <ChildUpdates renderAnchor={true} anchorClassOn={false}/>;
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
instance.setProps({anchorClassOn: true}); // Warm any cache
instance.setProps({renderAnchor: false}); // Clear out the anchor
// rerender
@@ -168,38 +168,37 @@ describe('ReactCompositeComponent', function() {
});
var instance = <ComponentClass />;
// These are controversial assertions for now, they just exist
// because existing code depends on these assumptions.
// These are expected to log a warning. This use case will be deprecated.
expect(function() {
instance.methodToBeExplicitlyBound.bind(instance)();
}).not.toThrow();
expect(function() {
instance.methodAutoBound();
}).not.toThrow();
expect(function() {
instance.methodExplicitlyNotBound();
}).not.toThrow();
// Next, prove that once mounted, the scope is bound correctly to the actual
// component.
var mountedInstance = ReactTestUtils.renderIntoDocument(instance);
expect(console.warn.argsForCall.length).toBe(3);
// This will result in a warning that has already been issued before.
var explicitlyBound = instance.methodToBeExplicitlyBound.bind(instance);
expect(console.warn.argsForCall.length).toBe(3);
var autoBound = instance.methodAutoBound;
var explicitlyNotBound = instance.methodExplicitlyNotBound;
expect(function() {
mountedInstance.methodToBeExplicitlyBound.bind(instance)();
}).not.toThrow();
expect(function() {
mountedInstance.methodAutoBound();
}).not.toThrow();
expect(function() {
mountedInstance.methodExplicitlyNotBound();
}).not.toThrow();
expect(console.warn.argsForCall.length).toBe(1);
var explicitlyBound = mountedInstance.methodToBeExplicitlyBound.bind(
mountedInstance
);
expect(console.warn.argsForCall.length).toBe(2);
var autoBound = mountedInstance.methodAutoBound;
var explicitlyNotBound = mountedInstance.methodExplicitlyNotBound;
var context = {};
expect(explicitlyBound.call(context)).toBe(mountedInstance);
expect(autoBound.call(context)).toBe(mountedInstance);
expect(explicitlyNotBound.call(context)).toBe(context);
expect(explicitlyBound.call(instance)).toBe(mountedInstance);
expect(autoBound.call(instance)).toBe(mountedInstance);
expect(explicitlyBound.call(mountedInstance)).toBe(mountedInstance);
expect(autoBound.call(mountedInstance)).toBe(mountedInstance);
// This one is the weird one
expect(explicitlyNotBound.call(instance)).toBe(mountedInstance);
expect(explicitlyNotBound.call(mountedInstance)).toBe(mountedInstance);
});
@@ -214,15 +213,15 @@ describe('ReactCompositeComponent', function() {
});
var instance1 = <Component />;
ReactTestUtils.renderIntoDocument(instance1);
instance1 = ReactTestUtils.renderIntoDocument(instance1);
reactComponentExpect(instance1).scalarPropsEqual({key: 'testKey'});
var instance2 = <Component key={undefined} />;
ReactTestUtils.renderIntoDocument(instance2);
instance2 = ReactTestUtils.renderIntoDocument(instance2);
reactComponentExpect(instance2).scalarPropsEqual({key: 'testKey'});
var instance3 = <Component key={null} />;
ReactTestUtils.renderIntoDocument(instance3);
instance3 = ReactTestUtils.renderIntoDocument(instance3);
reactComponentExpect(instance3).scalarPropsEqual({key: null});
});
@@ -238,7 +237,7 @@ describe('ReactCompositeComponent', function() {
var inputProps = {};
var instance1 = Component(inputProps);
ReactTestUtils.renderIntoDocument(instance1);
instance1 = ReactTestUtils.renderIntoDocument(instance1);
expect(instance1.props.key).toBe('testKey');
// We don't mutate the input, just in case the caller wants to do something
@@ -410,7 +409,7 @@ describe('ReactCompositeComponent', function() {
'mounted or mounting components.'
);
React.renderComponent(instance, container);
instance = React.renderComponent(instance, container);
expect(function() {
instance.forceUpdate();
}).not.toThrow();
@@ -435,7 +434,7 @@ describe('ReactCompositeComponent', function() {
expect(ReactCurrentOwner.current).toBe(null);
expect(function() {
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
}).toThrow();
expect(ReactCurrentOwner.current).toBe(null);
@@ -457,7 +456,7 @@ describe('ReactCompositeComponent', function() {
}
});
var instance = <Component />;
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
expect(instance.state.component).toBe(true);
expect(instance.state.mixin).toBe(true);
});
@@ -479,7 +478,7 @@ describe('ReactCompositeComponent', function() {
});
var instance = <Component />;
expect(function() {
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
}).toThrow(
'Invariant Violation: mergeObjectsWithNoDuplicateKeys(): ' +
'Tried to merge two objects with the same key: x'
@@ -498,7 +497,7 @@ describe('ReactCompositeComponent', function() {
}
});
var instance = <Component />;
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
expect(instance.state.occupation).toEqual('clown');
});
@@ -514,7 +513,7 @@ describe('ReactCompositeComponent', function() {
});
var instance = <Component />;
expect(function() {
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
}).toThrow(
'Invariant Violation: Component.getInitialState(): ' +
'must return an object or null'
@@ -559,7 +558,7 @@ describe('ReactCompositeComponent', function() {
).not.toThrow();
instance = <Component />;
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
expect(instance.state).toEqual({foo: 'bar'});
// Also the other way round should work
@@ -582,7 +581,7 @@ describe('ReactCompositeComponent', function() {
).not.toThrow();
instance = <Component />;
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
expect(instance.state).toEqual({foo: 'bar'});
// Multiple mixins should be fine too
@@ -600,7 +599,7 @@ describe('ReactCompositeComponent', function() {
).not.toThrow();
instance = <Component />;
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
expect(instance.state).toEqual({foo: 'bar', x: true});
});
@@ -616,7 +615,7 @@ describe('ReactCompositeComponent', function() {
}
});
var instance = <Component />;
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
expect(instance.state.occupation).toEqual('clown');
});
@@ -632,7 +631,7 @@ describe('ReactCompositeComponent', function() {
});
var instance = <Component />;
expect(function() {
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
}).toThrow(
'Invariant Violation: Component.getInitialState(): ' +
'must return an object or null'
@@ -803,8 +802,7 @@ describe('ReactCompositeComponent', function() {
},
render: function() {
childInstance = <Child />;
return childInstance;
return <Child />;
}
});
@@ -825,8 +823,8 @@ describe('ReactCompositeComponent', function() {
},
render: function() {
grandchildInstance = <Grandchild />;
return grandchildInstance;
childInstance = this;
return <Grandchild />;
}
});
@@ -837,12 +835,12 @@ describe('ReactCompositeComponent', function() {
},
render: function() {
grandchildInstance = this;
return <div />;
}
});
var instance = <Parent />;
ReactTestUtils.renderIntoDocument(instance);
ReactTestUtils.renderIntoDocument(<Parent />);
reactComponentExpect(childInstance).scalarContextEqual({foo: 'bar', depth: 0});
reactComponentExpect(grandchildInstance).scalarContextEqual({foo: 'bar', depth: 1});
});
@@ -940,7 +938,7 @@ describe('ReactCompositeComponent', function() {
var instance = React.withContext({foo: 'abc', bar: 123}, function() {
return <Component />;
});
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
reactComponentExpect(instance).scalarContextEqual({foo: 'abc'});
});
@@ -997,7 +995,7 @@ describe('ReactCompositeComponent', function() {
});
var instance = <Parent foo="abc" />;
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
instance.replaceProps({foo: "def"});
expect(actualComponentWillReceiveProps).toEqual({foo: 'def'});
expect(actualShouldComponentUpdate).toEqual({foo: 'def'});
@@ -1019,7 +1017,7 @@ describe('ReactCompositeComponent', function() {
}
});
var instance = <Component />;
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
expect(instance.constructor.abc).toBe('def');
expect(Component.abc).toBe('def');
expect(instance.constructor.def).toBe(0);
@@ -1048,7 +1046,7 @@ describe('ReactCompositeComponent', function() {
}
});
var instance = <Component />;
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
expect(instance.constructor.foo).toBe('bar');
expect(Component.foo).toBe('bar');
expect(instance.constructor.abc).toBe('def');
@@ -1132,7 +1130,7 @@ describe('ReactCompositeComponent', function() {
}
});
var instance = <Component />;
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
});
it('should include the mixin keys in even if their values are falsy',
@@ -1153,7 +1151,7 @@ describe('ReactCompositeComponent', function() {
}
});
var instance = <Component />;
ReactTestUtils.renderIntoDocument(instance);
instance = ReactTestUtils.renderIntoDocument(instance);
});
it('should warn if an umounted component is touched', function() {