From 2d6b4ab7b428ade915be52611119e11fc422c126 Mon Sep 17 00:00:00 2001 From: Maxim DOVHOPOLYI Date: Mon, 7 Feb 2022 20:07:24 +0200 Subject: [PATCH] chore: more tests --- src/decorators/is-object.spec.ts | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/decorators/is-object.spec.ts b/src/decorators/is-object.spec.ts index f5a7fc7..6c27c77 100644 --- a/src/decorators/is-object.spec.ts +++ b/src/decorators/is-object.spec.ts @@ -82,6 +82,46 @@ describe('IsObject', () => { expect(await input(Test, { objectField: false })).toStrictEqual( Result.err('objectField must be an object') ); + expect(await input(Test, { objectField: undefined })).toStrictEqual( + Result.err('objectField must be an object') + ); + expect(await input(Test, { objectField: null })).toStrictEqual( + Result.err('objectField must be an object') + ); + }); + + it('works with minProperties && nullable', async () => { + class Test { + @IsObject({ minProperties: 1, nullable: true }) + objectField!: Record | null; + } + + expect(await input(Test, { objectField: { a: 1 } })).toStrictEqual( + Result.ok(make(Test, { objectField: { a: 1 } })) + ); + expect(await input(Test, { objectField: { a: undefined } })).toStrictEqual( + Result.err('objectField must have at least 1 properties') + ); + expect(await input(Test, { objectField: { a: null } })).toStrictEqual( + Result.ok(make(Test, { objectField: { a: null } })) + ); + }) + + it('works with maxProperties && optional', async () => { + class Test { + @IsObject({ maxProperties: 1, optional: true }) + objectField!: Record; + } + + expect(await input(Test, { objectField: { a: 1 } })).toStrictEqual( + Result.ok(make(Test, { objectField: { a: 1 } })) + ); + expect(await input(Test, { objectField: { a: undefined } })).toStrictEqual( + Result.ok(make(Test, { objectField: {} })) + ); + expect(await input(Test, { objectField: { a: null } })).toStrictEqual( + Result.ok(make(Test, { objectField: { a: null } })) + ); }); });