From f88936977fadaf41050af22b0a6115479021e711 Mon Sep 17 00:00:00 2001 From: Justin Jaffray Date: Wed, 9 Apr 2014 22:23:43 -0700 Subject: [PATCH] Add tests for oneOfType with shape --- src/core/__tests__/ReactPropTypes-test.js | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/core/__tests__/ReactPropTypes-test.js b/src/core/__tests__/ReactPropTypes-test.js index 8bdccecb0e..e7a0220483 100644 --- a/src/core/__tests__/ReactPropTypes-test.js +++ b/src/core/__tests__/ReactPropTypes-test.js @@ -459,6 +459,16 @@ describe('Union Types', function() { [], 'Invalid prop `testProp` supplied to `testComponent`.' ); + + var checker = PropTypes.oneOfType([ + PropTypes.shape({a: PropTypes.number.isRequired}), + PropTypes.shape({b: PropTypes.number.isRequired}) + ]); + typeCheckFail( + checker, + {c: 1}, + 'Invalid prop `testProp` supplied to `testComponent`.' + ); }); it('should not warn if one of the types are valid', function() { @@ -469,6 +479,13 @@ describe('Union Types', function() { typeCheckPass(checker, null); typeCheckPass(checker, 'foo'); typeCheckPass(checker, 123); + + checker = PropTypes.oneOfType([ + PropTypes.shape({a: PropTypes.number.isRequired}), + PropTypes.shape({b: PropTypes.number.isRequired}) + ]); + typeCheckPass(checker, {a: 1}); + typeCheckPass(checker, {b: 1}); }); it("should be implicitly optional and not warn without values", function() { @@ -536,6 +553,17 @@ describe('Shape Types', function() { ); }); + it("should warn for the first required type", function() { + typeCheckFail( + PropTypes.shape({ + key: PropTypes.number.isRequired, + secondKey: PropTypes.number.isRequired + }), + {}, + 'Required prop `key` was not specified in `testComponent`.' + ); + }); + it("should warn for invalid key types", function() { typeCheckFail(PropTypes.shape({key: PropTypes.number}), {key: 'abc'},