Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/isomorphic/classic/types/ReactPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ function createInstanceTypeChecker(expectedClass) {
}

function createEnumTypeChecker(expectedValues) {
if (!Array.isArray(expectedValues)) {
return new Error(
`Invalid argument supplied to oneOf, expected an instance of array.`
);
}

function validate(props, propName, componentName, location, propFullName) {
var propValue = props[propName];
for (var i = 0; i < expectedValues.length; i++) {
Expand Down Expand Up @@ -249,6 +255,12 @@ function createObjectOfTypeChecker(typeChecker) {
}

function createUnionTypeChecker(arrayOfTypeCheckers) {
if (!Array.isArray(arrayOfTypeCheckers)) {
return new Error(
`Invalid argument supplied to oneOfType, expected an instance of array.`
);
}

function validate(props, propName, componentName, location, propFullName) {
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
var checker = arrayOfTypeCheckers[i];
Expand Down
14 changes: 14 additions & 0 deletions src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,13 @@ describe('ReactPropTypes', function() {
});

describe('OneOf Types', function() {
it("should fail for invalid argument", function() {
var error = PropTypes.oneOf('red', 'blue');
expect(error instanceof Error).toBe(true);
expect(error.message).toBe('Invalid argument supplied to ' +
'oneOf, expected an instance of array.');
});

it("should warn for invalid strings", function() {
typeCheckFail(
PropTypes.oneOf(['red', 'blue']),
Expand Down Expand Up @@ -572,6 +579,13 @@ describe('ReactPropTypes', function() {
});

describe('Union Types', function() {
it("should fail for invalid argument", function() {
var error = PropTypes.oneOfType('red', 'blue');
expect(error instanceof Error).toBe(true);
expect(error.message).toBe('Invalid argument supplied to ' +
'oneOfType, expected an instance of array.');
});

it('should warn if none of the types are valid', function() {
typeCheckFail(
PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
Expand Down