Added tests for the new primative, Symbol.
I believe that I covered all the typical use cases for Symbols. If you think that I missed one, feel free to contribute.
Sam Balana committed
Mar 29, 2016 at 17:20 UTC
75c4e037183ec99d6e961d3710cfb0f19b0415dd
1 file changed
+19
src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
+19
@@ -80,6 +80,12 @@ describe('ReactPropTypes', function() {
80
'Invalid prop `testProp` of type `object` supplied to ' +
81
'`testComponent`, expected `string`.'
82
);
83
+ typeCheckFail(
84
+ PropTypes.string,
85
+ Symbol(),
86
+ 'Invalid prop `testProp` of type `symbol` supplied to ' +
87
+ '`testComponent`, expected `string`.'
88
+ );
89
});
90
91
it('should fail date and regexp correctly', function() {
@@ -106,6 +112,7 @@ describe('ReactPropTypes', function() {
112
typeCheckPass(PropTypes.object, {});
113
typeCheckPass(PropTypes.object, new Date());
114
typeCheckPass(PropTypes.object, /please/);
115
+ typeCheckPass(PropTypes.symbol, Symbol());
116
});
117
118
it('should be implicitly optional and not warn without values', function() {
@@ -124,6 +131,7 @@ describe('ReactPropTypes', function() {
131
typeCheckPass(PropTypes.any, 0);
132
typeCheckPass(PropTypes.any, 'str');
133
typeCheckPass(PropTypes.any, []);
134
+ typeCheckPass(PropTypes.any, Symbol());
135
});
136
137
it('should be implicitly optional and not warn without values', function() {
@@ -150,6 +158,7 @@ describe('ReactPropTypes', function() {
158
typeCheckPass(PropTypes.arrayOf(PropTypes.number), [1, 2, 3]);
159
typeCheckPass(PropTypes.arrayOf(PropTypes.string), ['a', 'b', 'c']);
160
typeCheckPass(PropTypes.arrayOf(PropTypes.oneOf(['a', 'b'])), ['a', 'b']);
161
+ typeCheckPass(PropTypes.arrayOf(PropTypes.symbol), [Symbol(), Symbol()]);
162
});
163
164
it('should support arrayOf with complex types', function() {
@@ -487,6 +496,10 @@ describe('ReactPropTypes', function() {
496
PropTypes.objectOf(PropTypes.oneOf(['a', 'b'])),
497
{a: 'a', b: 'b'}
498
);
499
+ typeCheckPass(
500
+ PropTypes.objectOf(PropTypes.symbol),
501
+ {a: Symbol(), b: Symbol(), c: Symbol()}
502
+ );
503
});
504
505
it('should support objectOf with complex types', function() {
@@ -542,6 +555,12 @@ describe('ReactPropTypes', function() {
555
'Invalid prop `testProp` of type `string` supplied to ' +
556
'`testComponent`, expected an object.'
557
);
558
+ typeCheckFail(
559
+ PropTypes.objectOf(PropTypes.symbol),
560
+ Symbol(),
561
+ 'Invalid prop `testProp` of type `symbol` supplied to ' +
562
+ '`testComponent`, expected an object.'
563
+ );
564
});
565
566
it('should not warn when passing an empty object', function() {