Drop internal uses of .type on the class

This commit is contained in:
Sebastian Markbage
2014-10-28 15:08:52 -07:00
parent 199a7d6903
commit 9b36b04d75
6 changed files with 16 additions and 26 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ function createInstanceForTag(tag, props, parentType) {
return new genericComponentClass(tag, props);
}
// Unwrap legacy factories
return new componentClass.type(props);
return new componentClass(props);
}
var ReactNativeComponent = {
@@ -1237,8 +1237,8 @@ describe('ReactCompositeComponent', function() {
expect(Component.ghi).toBe(null);
expect(instance.constructor.jkl).toBe('mno');
expect(Component.jkl).toBe('mno');
expect(instance.constructor.pqr()).toBe(Component.type);
expect(Component.pqr()).toBe(Component.type);
expect(instance.constructor.pqr()).toBe(Component);
expect(Component.pqr()).toBe(Component);
});
it('should throw if a reserved property is in statics', function() {
@@ -152,8 +152,8 @@ describe('ReactCompositeComponent-mixin', function() {
});
it('should validate prop types via mixins', function() {
expect(TestComponent.type.propTypes).toBeDefined();
expect(TestComponent.type.propTypes.value)
expect(TestComponent.propTypes).toBeDefined();
expect(TestComponent.propTypes.value)
.toBe(mixinPropValidator);
});
@@ -161,11 +161,11 @@ describe('ReactCompositeComponent-mixin', function() {
// Sanity check...
expect(componentPropValidator).toNotBe(mixinPropValidator);
// Actually check...
expect(TestComponentWithPropTypes.type.propTypes)
expect(TestComponentWithPropTypes.propTypes)
.toBeDefined();
expect(TestComponentWithPropTypes.type.propTypes.value)
expect(TestComponentWithPropTypes.propTypes.value)
.toNotBe(mixinPropValidator);
expect(TestComponentWithPropTypes.type.propTypes.value)
expect(TestComponentWithPropTypes.propTypes.value)
.toBe(componentPropValidator);
});
});
@@ -41,7 +41,7 @@ describe('ReactCompositeComponent-spec', function() {
}
});
expect(TestComponent.type.displayName)
expect(TestComponent.displayName)
.toBe('TestComponent');
});
@@ -56,8 +56,8 @@ describe('ReactCompositeComponent-spec', function() {
}
});
expect(TestComponent.type.propTypes).toBeDefined();
expect(TestComponent.type.propTypes.value)
expect(TestComponent.propTypes).toBeDefined();
expect(TestComponent.propTypes.value)
.toBe(propValidator);
});
});
+1 -8
View File
@@ -26,7 +26,7 @@ describe('ReactElement', function() {
ComponentFactory = React.createClass({
render: function() { return <div />; }
});
ComponentClass = ComponentFactory.type;
ComponentClass = ComponentFactory;
});
it('returns a complete element according to spec', function() {
@@ -338,13 +338,6 @@ describe('ReactElement', function() {
expect(ReactElement.isValidElement(Component)).toEqual(false);
});
it('should expose the underlying class from a legacy factory', function() {
var Legacy = React.createClass({ render: function() { } });
var factory = React.createFactory(Legacy);
expect(factory.type).toBe(Legacy.type);
expect(factory().type).toBe(Legacy.type);
});
it('allows the use of PropTypes validators in statics', function() {
var Component = React.createClass({
render: () => null,
+4 -7
View File
@@ -97,12 +97,9 @@ assign(reactComponentExpect.prototype, {
// Matchers ------------------------------------------------------------------
toBeComponentOfType: function(convenienceConstructor) {
var type = typeof convenienceConstructor === 'string' ?
convenienceConstructor :
convenienceConstructor.type;
toBeComponentOfType: function(constructor) {
expect(
this.instance()._currentElement.type === type
this.instance()._currentElement.type === constructor
).toBe(true);
return this;
},
@@ -119,10 +116,10 @@ assign(reactComponentExpect.prototype, {
return this;
},
toBeCompositeComponentWithType: function(convenienceConstructor) {
toBeCompositeComponentWithType: function(constructor) {
this.toBeCompositeComponent();
expect(
this.instance()._currentElement.type === convenienceConstructor.type
this.instance()._currentElement.type === constructor
).toBe(true);
return this;
},