Skip to content

Commit

Permalink
Test if warnings occur when a mixin is undefined or null
Browse files Browse the repository at this point in the history
  • Loading branch information
Swaroop SM committed Mar 1, 2016
1 parent 3a37e77 commit 8341f31
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/isomorphic/classic/class/__tests__/ReactClassMixin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,46 @@ describe('ReactClass-mixin', function() {
);
});

it('should warn if the mixin is undefined', function() {
spyOn(console, 'error');

var Mixin = undefined;

React.createClass({
mixins: [Mixin],

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. Expected object but got undefined'
);
});

it('should warn if the mixin is null', function() {
spyOn(console, 'error');

var Mixin = null;

React.createClass({
mixins: [Mixin],

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. Expected object but got null'
);
});

it('should throw if the mixin is a React component', function() {
expect(function() {
React.createClass({
Expand Down

0 comments on commit 8341f31

Please sign in to comment.