Add tests for oneOfType with shape
Justin Jaffray committed
Apr 9, 2014 at 22:23 UTC
f88936977fadaf41050af22b0a6115479021e711
1 file changed
+28
src/core/__tests__/ReactPropTypes-test.js
+28
@@ -459,6 +459,16 @@ describe('Union Types', function() {
459
[],
460
'Invalid prop `testProp` supplied to `testComponent`.'
461
);
462
+
463
+ var checker = PropTypes.oneOfType([
464
+ PropTypes.shape({a: PropTypes.number.isRequired}),
465
+ PropTypes.shape({b: PropTypes.number.isRequired})
466
+ ]);
467
+ typeCheckFail(
468
+ checker,
469
+ {c: 1},
470
+ 'Invalid prop `testProp` supplied to `testComponent`.'
471
+ );
472
});
473
474
it('should not warn if one of the types are valid', function() {
@@ -469,6 +479,13 @@ describe('Union Types', function() {
479
typeCheckPass(checker, null);
480
typeCheckPass(checker, 'foo');
481
typeCheckPass(checker, 123);
482
+
483
+ checker = PropTypes.oneOfType([
484
+ PropTypes.shape({a: PropTypes.number.isRequired}),
485
+ PropTypes.shape({b: PropTypes.number.isRequired})
486
+ ]);
487
+ typeCheckPass(checker, {a: 1});
488
+ typeCheckPass(checker, {b: 1});
489
});
490
491
it("should be implicitly optional and not warn without values", function() {
@@ -536,6 +553,17 @@ describe('Shape Types', function() {
553
);
554
});
555
556
+ it("should warn for the first required type", function() {
557
+ typeCheckFail(
558
+ PropTypes.shape({
559
+ key: PropTypes.number.isRequired,
560
+ secondKey: PropTypes.number.isRequired
561
+ }),
562
+ {},
563
+ 'Required prop `key` was not specified in `testComponent`.'
564
+ );
565
+ });
566
+
567
it("should warn for invalid key types", function() {
568
typeCheckFail(PropTypes.shape({key: PropTypes.number}),
569
{key: 'abc'},