-
Notifications
You must be signed in to change notification settings - Fork 46.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issues introduced by createElement() warning #6880
Changes from 6 commits
94d0dc6
f846edc
15cd66b
1b802fb
c77411b
d9ae319
a432afa
919eba3
55a0e4b
58c9fda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,7 +165,59 @@ describe('ReactElement', function() { | |
expect(element.type).toBe(ComponentClass); | ||
expect(element.key).toBe('12'); | ||
expect(element.ref).toBe('34'); | ||
var expectation = {foo:'56'}; | ||
var expectation = {foo: '56'}; | ||
Object.freeze(expectation); | ||
expect(element.props).toEqual(expectation); | ||
}); | ||
|
||
it('extracts null key and ref', function() { | ||
var element = React.createFactory(ComponentClass)({ | ||
key: null, | ||
ref: null, | ||
foo: '12', | ||
}); | ||
expect(element.type).toBe(ComponentClass); | ||
expect(element.key).toBe('null'); | ||
expect(element.ref).toBe(null); | ||
var expectation = {foo: '12'}; | ||
Object.freeze(expectation); | ||
expect(element.props).toEqual(expectation); | ||
}); | ||
|
||
it('ignores undefined key and ref', function() { | ||
var props = { | ||
foo: '56', | ||
key: undefined, | ||
ref: undefined, | ||
}; | ||
var element = React.createFactory(ComponentClass)(props); | ||
expect(element.type).toBe(ComponentClass); | ||
expect(element.key).toBe(null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So in prod mode these would have different behavior, right? :( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Not new, of course.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea. |
||
expect(element.ref).toBe(null); | ||
var expectation = {foo: '56'}; | ||
Object.freeze(expectation); | ||
expect(element.props).toEqual(expectation); | ||
}); | ||
|
||
it('ignores key and ref getters', function() { | ||
var props = { | ||
foo: '56', | ||
}; | ||
Object.defineProperty(props, 'key', { | ||
get: function() { | ||
return '12'; | ||
}, | ||
}); | ||
Object.defineProperty(props, 'ref', { | ||
get: function() { | ||
return '34'; | ||
}, | ||
}); | ||
var element = React.createFactory(ComponentClass)(props); | ||
expect(element.type).toBe(ComponentClass); | ||
expect(element.key).toBe(null); | ||
expect(element.ref).toBe(null); | ||
var expectation = {foo: '56'}; | ||
Object.freeze(expectation); | ||
expect(element.props).toEqual(expectation); | ||
}); | ||
|
@@ -178,7 +230,7 @@ describe('ReactElement', function() { | |
expect(element.type).toBe(ComponentClass); | ||
expect(element.key).toBe('12'); | ||
expect(element.ref).toBe(null); | ||
var expectation = {foo:'56'}; | ||
var expectation = {foo: '56'}; | ||
Object.freeze(expectation); | ||
expect(element.props).toEqual(expectation); | ||
}); | ||
|
@@ -229,18 +281,6 @@ describe('ReactElement', function() { | |
expect(console.error.calls.count()).toBe(0); | ||
}); | ||
|
||
it('overrides children if undefined is provided as an argument', function() { | ||
var element = React.createElement(ComponentClass, { | ||
children: 'text', | ||
}, undefined); | ||
expect(element.props.children).toBe(undefined); | ||
|
||
var element2 = React.cloneElement(React.createElement(ComponentClass, { | ||
children: 'text', | ||
}), {}, undefined); | ||
expect(element2.props.children).toBe(undefined); | ||
}); | ||
|
||
it('merges rest arguments onto the children prop in an array', function() { | ||
spyOn(console, 'error'); | ||
var a = 1; | ||
|
@@ -370,29 +410,6 @@ describe('ReactElement', function() { | |
expect(inst2.props.prop).toBe(null); | ||
}); | ||
|
||
it('should normalize props with default values in cloning', function() { | ||
var Component = React.createClass({ | ||
getDefaultProps: function() { | ||
return {prop: 'testKey'}; | ||
}, | ||
render: function() { | ||
return <span />; | ||
}, | ||
}); | ||
|
||
var instance = React.createElement(Component); | ||
var clonedInstance = React.cloneElement(instance, {prop: undefined}); | ||
expect(clonedInstance.props.prop).toBe('testKey'); | ||
var clonedInstance2 = React.cloneElement(instance, {prop: null}); | ||
expect(clonedInstance2.props.prop).toBe(null); | ||
|
||
var instance2 = React.createElement(Component, {prop: 'newTestKey'}); | ||
var cloneInstance3 = React.cloneElement(instance2, {prop: undefined}); | ||
expect(cloneInstance3.props.prop).toBe('testKey'); | ||
var cloneInstance4 = React.cloneElement(instance2, {}); | ||
expect(cloneInstance4.props.prop).toBe('newTestKey'); | ||
}); | ||
|
||
it('throws when changing a prop (in dev) after element creation', function() { | ||
var Outer = React.createClass({ | ||
render: function() { | ||
|
@@ -583,4 +600,5 @@ describe('comparing jsx vs .createFactory() vs .createElement()', function() { | |
expect(Child.mock.calls[0][0]).toEqual({ foo: 'foo value', children: 'children value' }); | ||
}); | ||
}); | ||
|
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the freezes for? (I guess they were here already too…)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea 😄 . They were there and spread like fire. I wouldn’t be surprised if the first freeze was added for a completely unrelated purpose. (Maybe from the pre-element times?)