Add reactComponentExpect#toBeComponentOfType

This adds a `toBeComponentOfType` method to `reactComponentExpect`. Now that we are injecting composite native components, `toBeDOMComponentWithTag` will not suffice and should be deprecated.
This commit is contained in:
CommitSyncScript
2013-06-21 16:02:55 -07:00
committed by Paul O’Shannessy
parent 18352090e7
commit 36a724feca
4 changed files with 26 additions and 5 deletions
+3 -2
View File
@@ -41,15 +41,16 @@ var objMapKeyVal = require('objMapKeyVal');
*/
function createDOMComponentClass(tag, omitClose) {
var Constructor = function() {};
Constructor.prototype = new ReactNativeComponent(tag, omitClose);
Constructor.prototype.constructor = Constructor;
return function(props, children) {
var ConvenienceConstructor = function(props, children) {
var instance = new Constructor();
instance.construct.apply(instance, arguments);
return instance;
};
ConvenienceConstructor.componentConstructor = Constructor;
return ConvenienceConstructor;
}
/**
@@ -52,7 +52,7 @@ describe('ReactCompositeComponent-transferProps', function() {
reactComponentExpect(instance)
.expectRenderedChild()
.toBeDOMComponentWithTag('input')
.toBeComponentOfType(React.DOM.input)
.scalarPropsEqual({
className: 'textinput',
style: {display: 'block'},
@@ -67,7 +67,7 @@ describe('ReactCompositeComponent-transferProps', function() {
reactComponentExpect(instance)
.expectRenderedChild()
.toBeDOMComponentWithTag('input')
.toBeComponentOfType(React.DOM.input)
.scalarPropsEqual({placeholder: 'Type here...'});
});
@@ -81,7 +81,7 @@ describe('ReactCompositeComponent-transferProps', function() {
reactComponentExpect(instance)
.expectRenderedChild()
.toBeDOMComponentWithTag('input')
.toBeComponentOfType(React.DOM.input)
.scalarPropsEqual({
className: 'textinput hidden_elem',
style: {
+8
View File
@@ -45,6 +45,14 @@ var ReactTestUtils = {
return React.renderComponent(instance, div);
},
isComponentOfType: function(inst, type) {
return !!(
inst &&
ReactComponent.isValidComponent(inst) &&
inst.constructor === type.componentConstructor
);
},
isDOMComponent: function(inst) {
return !!(inst &&
ReactComponent.isValidComponent(inst) &&
+12
View File
@@ -104,6 +104,14 @@ mergeInto(reactComponentExpect.prototype, {
// Matchers ------------------------------------------------------------------
toBeComponentOfType: function(convenienceConstructor) {
expect(ReactTestUtils.isComponentOfType(
this.instance(),
convenienceConstructor
)).toBe(true);
return this;
},
/**
* A component that is created with React.createClass. Just duck typing
* here.
@@ -149,6 +157,10 @@ mergeInto(reactComponentExpect.prototype, {
return this;
},
/**
* @deprecated
* @see toBeComponentOfType
*/
toBeDOMComponentWithTag: function(tag) {
this.toBeDOMComponent();
expect(this.instance().tagName).toBe(tag.toUpperCase());