@samitouri / QOS-React-2 / commits / bcfb476366

More tests for 77697f26e32e1625397e6cdcb0defe0a746b7230

Christoph Pojer committed Jan 2, 2014 at 19:42 UTC bcfb4763668b1e2417b581f7e218d15b7fb5c88c
1 file changed +36
src/core/__tests__/ReactCompositeComponent-test.js
+36
@@ -458,6 +458,42 @@ describe('ReactCompositeComponent', function() {
458 );
459 });
460
461 + it('should work with object getInitialState() return values', function() {
462 + var Component = React.createClass({
463 + getInitialState: function() {
464 + return {
465 + occupation: 'clown'
466 + };
467 + },
468 + render: function() {
469 + return <span />;
470 + }
471 + });
472 + var instance = <Component />;
473 + ReactTestUtils.renderIntoDocument(instance);
474 + expect(instance.state.occupation).toEqual('clown');
475 + });
476 +
477 + it('should throw with non-object getInitialState() return values', function() {
478 + [['an array'], 'a string', 1234].forEach(function(state) {
479 + var Component = React.createClass({
480 + getInitialState: function() {
481 + return state;
482 + },
483 + render: function() {
484 + return <span />;
485 + }
486 + });
487 + var instance = <Component />;
488 + expect(function() {
489 + ReactTestUtils.renderIntoDocument(instance);
490 + }).toThrow(
491 + 'Invariant Violation: Component.getInitialState(): ' +
492 + 'must return an object or null'
493 + );
494 + });
495 + });
496 +
497 it('should work with a null getInitialState() return value', function() {
498 var Component = React.createClass({
499 getInitialState: function() {