mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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:
committed by
Paul O’Shannessy
parent
18352090e7
commit
36a724feca
@@ -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: {
|
||||
|
||||
@@ -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) &&
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user