mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Warn if the included mixin is undefined (#6158)
(cherry picked from commit 18bad0669f)
This commit is contained in:
1 parent
3b80d4dcd7
commit
9d385ef326
2 files changed
+103
No files matched your search
@@ -436,6 +436,21 @@ function validateMethodOverride(isAlreadyDefined, name) {
|
||||
*/
|
||||
function mixSpecIntoComponent(Constructor, spec) {
|
||||
if (!spec) {
|
||||
if (__DEV__) {
|
||||
var typeofSpec = typeof spec;
|
||||
var isMixinValid = typeofSpec === 'object' && spec !== null;
|
||||
|
||||
warning(
|
||||
isMixinValid,
|
||||
'%s: You\'re attempting to include a mixin that is either null ' +
|
||||
'or not an object. Check the mixins included by the component, ' +
|
||||
'as well as any mixins they include themselves. ' +
|
||||
'Expected object but got %s.',
|
||||
Constructor.displayName || 'ReactClass',
|
||||
spec === null ? null : typeofSpec
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -310,6 +310,94 @@ describe('ReactClass-mixin', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn if the mixin is undefined', function() {
|
||||
spyOn(console, 'error');
|
||||
|
||||
React.createClass({
|
||||
mixins: [undefined],
|
||||
|
||||
render: function() {
|
||||
return <span />;
|
||||
},
|
||||
});
|
||||
|
||||
expect(console.error.argsForCall.length).toBe(1);
|
||||
expect(console.error.argsForCall[0][0]).toBe(
|
||||
'Warning: ReactClass: You\'re attempting to include a mixin that is ' +
|
||||
'either null or not an object. Check the mixins included by the ' +
|
||||
'component, as well as any mixins they include themselves. ' +
|
||||
'Expected object but got undefined.'
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn if the mixin is null', function() {
|
||||
spyOn(console, 'error');
|
||||
|
||||
React.createClass({
|
||||
mixins: [null],
|
||||
|
||||
render: function() {
|
||||
return <span />;
|
||||
},
|
||||
});
|
||||
|
||||
expect(console.error.argsForCall.length).toBe(1);
|
||||
expect(console.error.argsForCall[0][0]).toBe(
|
||||
'Warning: ReactClass: You\'re attempting to include a mixin that is ' +
|
||||
'either null or not an object. Check the mixins included by the ' +
|
||||
'component, as well as any mixins they include themselves. ' +
|
||||
'Expected object but got null.'
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn if an undefined mixin is included in another mixin', function() {
|
||||
spyOn(console, 'error');
|
||||
|
||||
var mixinA = {
|
||||
mixins: [undefined],
|
||||
};
|
||||
|
||||
React.createClass({
|
||||
mixins: [mixinA],
|
||||
|
||||
render: function() {
|
||||
return <span />;
|
||||
},
|
||||
});
|
||||
|
||||
expect(console.error.argsForCall.length).toBe(1);
|
||||
expect(console.error.argsForCall[0][0]).toBe(
|
||||
'Warning: ReactClass: You\'re attempting to include a mixin that is ' +
|
||||
'either null or not an object. Check the mixins included by the ' +
|
||||
'component, as well as any mixins they include themselves. ' +
|
||||
'Expected object but got undefined.'
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn if a null mixin is included in another mixin', function() {
|
||||
spyOn(console, 'error');
|
||||
|
||||
var mixinA = {
|
||||
mixins: [null],
|
||||
};
|
||||
|
||||
React.createClass({
|
||||
mixins: [mixinA],
|
||||
|
||||
render: function() {
|
||||
return <span />;
|
||||
},
|
||||
});
|
||||
|
||||
expect(console.error.argsForCall.length).toBe(1);
|
||||
expect(console.error.argsForCall[0][0]).toBe(
|
||||
'Warning: ReactClass: You\'re attempting to include a mixin that is ' +
|
||||
'either null or not an object. Check the mixins included by the ' +
|
||||
'component, as well as any mixins they include themselves. ' +
|
||||
'Expected object but got null.'
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw if the mixin is a React component', function() {
|
||||
expect(function() {
|
||||
React.createClass({
|
||||
|
||||
Reference in new issue
Block a user