|
1 | 1 | import {type Type, t} from '..'; |
| 2 | +import {ValidationError, ValidationErrorMessage} from '../../constants'; |
2 | 3 | import {TypeSystem} from '../../system/TypeSystem'; |
3 | 4 |
|
4 | 5 | export const validateTestSuite = (validate: (type: Type, value: unknown) => void) => { |
@@ -384,6 +385,22 @@ export const validateTestSuite = (validate: (type: Type, value: unknown) => void |
384 | 385 | expect(() => validate(type, [1])).toThrowErrorMatchingInlineSnapshot(`"STR"`); |
385 | 386 | }); |
386 | 387 |
|
| 388 | + test('object nested in array', () => { |
| 389 | + const type = t.obj |
| 390 | + .prop('foo', t.array(t.obj.prop('bar', t.str))) |
| 391 | + validate(type, {foo: [{bar: 'baz'}]}); |
| 392 | + const validator = type.validator('object'); |
| 393 | + const res = validator({foo: [{bar: 'baz'}]}); |
| 394 | + expect(res).toBe(null); |
| 395 | + const res2 = validator({foo: {bar: 'baz'}}); |
| 396 | + expect(res2).toEqual({ |
| 397 | + code: ValidationError[ValidationError.ARR], |
| 398 | + errno: ValidationError.ARR, |
| 399 | + message: ValidationErrorMessage[ValidationError.ARR], |
| 400 | + path: [ 'foo' ] |
| 401 | + }); |
| 402 | + }); |
| 403 | + |
387 | 404 | describe('size bounds', () => { |
388 | 405 | test('respects min and max', () => { |
389 | 406 | const type = t.arr.options({min: 2, max: 4}); |
|
0 commit comments