Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/test/ReactTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var ReactElement = require('ReactElement');
var ReactBrowserEventEmitter = require('ReactBrowserEventEmitter');
var ReactCompositeComponent = require('ReactCompositeComponent');
var ReactInstanceMap = require('ReactInstanceMap');
var ReactInstrumentation = require('ReactInstrumentation');
var ReactReconciler = require('ReactReconciler');
var ReactUpdates = require('ReactUpdates');
var SyntheticEvent = require('SyntheticEvent');

Expand Down Expand Up @@ -407,7 +409,11 @@ NoopInternalComponent.prototype = {
};

var ShallowComponentWrapper = function(element) {
// TODO: Consolidate with instantiateReactComponent
this._debugID = nextDebugID++;
var displayName = element.type.displayName || element.type.name || 'Unknown';
ReactInstrumentation.debugTool.onSetDisplayName(this._debugID, displayName);

this.construct(element);
};
Object.assign(
Expand Down Expand Up @@ -471,16 +477,21 @@ ReactShallowRenderer.prototype.getRenderOutput = function() {

ReactShallowRenderer.prototype.unmount = function() {
if (this._instance) {
this._instance.unmountComponent(false);
ReactReconciler.unmountComponent(this._instance, false);
}
};

ReactShallowRenderer.prototype._render = function(element, transaction, context) {
if (this._instance) {
this._instance.receiveComponent(element, transaction, context);
ReactReconciler.receiveComponent(
this._instance,
element,
transaction,
context
);
} else {
var instance = new ShallowComponentWrapper(element);
instance.mountComponent(transaction, null, null, context);
ReactReconciler.mountComponent(instance, transaction, null, null, context);
this._instance = instance;
}
};
Expand Down
23 changes: 23 additions & 0 deletions src/test/__tests__/ReactTestUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,29 @@ describe('ReactTestUtils', function() {
expect(result).toEqual(<div>foo</div>);
});

it('can fail context when shallowly rendering', function() {
spyOn(console, 'error');
var SimpleComponent = React.createClass({
contextTypes: {
name: React.PropTypes.string.isRequired,
},
render: function() {
return <div>{this.context.name}</div>;
},
});

var shallowRenderer = ReactTestUtils.createRenderer();
shallowRenderer.render(<SimpleComponent />);
expect(console.error.argsForCall.length).toBe(1);
expect(
console.error.argsForCall[0][0].replace(/\(at .+?:\d+\)/g, '(at **)')
).toBe(
'Warning: Failed context type: Required context `name` was not ' +
'specified in `SimpleComponent`.\n' +
' in SimpleComponent (at **)'
);
});

it('can scryRenderedDOMComponentsWithClass with TextComponent', function() {
var Wrapper = React.createClass({
render: function() {
Expand Down