Skip to content

Commit be95c78

Browse files
authored
Merge pull request #405 from rvsia/fixOrCondition
fix(renderer): do not fail when using or
2 parents ffe95b7 + ffe1c10 commit be95c78

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

packages/react-form-renderer/src/files/default-schema-validator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ const checkCondition = (condition, fieldName) => {
3131
`);
3232
}
3333

34-
if (condition.hasOwnProperty('or') && !Array.isArray(condition.and)) {
34+
if (condition.hasOwnProperty('or') && !Array.isArray(condition.or)) {
3535
throw new DefaultSchemaError(`
3636
Error occured in field definition with "name" property: "${fieldName}".
37-
'or' propery in a field condition must be an array! Received: ${typeof condition.and}.
37+
'or' property in a field condition must be an array! Received: ${typeof condition.or}.
3838
`);
3939
}
4040

packages/react-form-renderer/src/tests/parsers/__snapshots__/default-schema-validator.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ exports[`Default schema validator should fail validation when using "and" and "o
127127
exports[`Default schema validator should fail validation when using "and" and "or" conditions 2`] = `
128128
"
129129
Error occured in field definition with \\"name\\" property: \\"foo\\".
130-
'or' propery in a field condition must be an array! Received: undefined.
130+
'or' property in a field condition must be an array! Received: object.
131131
"
132132
`;
133133

packages/react-form-renderer/src/tests/parsers/default-schema-validator.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,46 @@ describe('Default schema validator', () => {
482482
});
483483
});
484484

485+
it('should not fail validation using "and" and "or" conditions', () => {
486+
expect(() =>
487+
defaultSchemaValidator(
488+
{
489+
fields: [
490+
{
491+
component: 'foo',
492+
name: 'foo',
493+
condition: {
494+
and: [{ when: 'x', is: 'y' }]
495+
}
496+
}
497+
]
498+
},
499+
componentMapper,
500+
[],
501+
[]
502+
)
503+
).not.toThrow();
504+
505+
expect(() =>
506+
defaultSchemaValidator(
507+
{
508+
fields: [
509+
{
510+
component: 'foo',
511+
name: 'foo',
512+
condition: {
513+
or: [{ when: 'x', is: 'y' }]
514+
}
515+
}
516+
]
517+
},
518+
componentMapper,
519+
[],
520+
[]
521+
)
522+
).not.toThrow();
523+
});
524+
485525
it('should fail validation when using "and" and "or" conditions', () => {
486526
expect(() =>
487527
defaultSchemaValidator(

0 commit comments

Comments
 (0)