@samitouri / QOS-React-2 / commits / 36a724feca
Fork 0

The library for web and native user interfaces.

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.

CommitSyncScript committed Jun 21, 2013 at 13:48 UTC 36a724fecaed3c52ce8140683f452524934caceb
4 files changed +26 -5
src/core/ReactDOM.js
+3 -2
@@ -41,15 +41,16 @@ var objMapKeyVal = require('objMapKeyVal');
41 */
42 function createDOMComponentClass(tag, omitClose) {
43 var Constructor = function() {};
44 -
44 Constructor.prototype = new ReactNativeComponent(tag, omitClose);
45 Constructor.prototype.constructor = Constructor;
46
48 - return function(props, children) {
47 + var ConvenienceConstructor = function(props, children) {
48 var instance = new Constructor();
49 instance.construct.apply(instance, arguments);
50 return instance;
51 };
52 + ConvenienceConstructor.componentConstructor = Constructor;
53 + return ConvenienceConstructor;
54 }
55
56 /**
src/core/__tests__/ReactCompositeComponentTransferProps-test.js
+3 -3
@@ -52,7 +52,7 @@ describe('ReactCompositeComponent-transferProps', function() {
52
53 reactComponentExpect(instance)
54 .expectRenderedChild()
55 - .toBeDOMComponentWithTag('input')
55 + .toBeComponentOfType(React.DOM.input)
56 .scalarPropsEqual({
57 className: 'textinput',
58 style: {display: 'block'},
@@ -67,7 +67,7 @@ describe('ReactCompositeComponent-transferProps', function() {
67
68 reactComponentExpect(instance)
69 .expectRenderedChild()
70 - .toBeDOMComponentWithTag('input')
70 + .toBeComponentOfType(React.DOM.input)
71 .scalarPropsEqual({placeholder: 'Type here...'});
72 });
73
@@ -81,7 +81,7 @@ describe('ReactCompositeComponent-transferProps', function() {
81
82 reactComponentExpect(instance)
83 .expectRenderedChild()
84 - .toBeDOMComponentWithTag('input')
84 + .toBeComponentOfType(React.DOM.input)
85 .scalarPropsEqual({
86 className: 'textinput hidden_elem',
87 style: {
src/test/ReactTestUtils.js
+8
@@ -45,6 +45,14 @@ var ReactTestUtils = {
45 return React.renderComponent(instance, div);
46 },
47
48 + isComponentOfType: function(inst, type) {
49 + return !!(
50 + inst &&
51 + ReactComponent.isValidComponent(inst) &&
52 + inst.constructor === type.componentConstructor
53 + );
54 + },
55 +
56 isDOMComponent: function(inst) {
57 return !!(inst &&
58 ReactComponent.isValidComponent(inst) &&
src/test/reactComponentExpect.js
+12
@@ -104,6 +104,14 @@ mergeInto(reactComponentExpect.prototype, {
104
105 // Matchers ------------------------------------------------------------------
106
107 + toBeComponentOfType: function(convenienceConstructor) {
108 + expect(ReactTestUtils.isComponentOfType(
109 + this.instance(),
110 + convenienceConstructor
111 + )).toBe(true);
112 + return this;
113 + },
114 +
115 /**
116 * A component that is created with React.createClass. Just duck typing
117 * here.
@@ -149,6 +157,10 @@ mergeInto(reactComponentExpect.prototype, {
157 return this;
158 },
159
160 + /**
161 + * @deprecated
162 + * @see toBeComponentOfType
163 + */
164 toBeDOMComponentWithTag: function(tag) {
165 this.toBeDOMComponent();
166 expect(this.instance().tagName).toBe(tag.toUpperCase());