Skip to content

Commit

Permalink
chore: more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mdovhopo committed Feb 7, 2022
1 parent 6250143 commit 2d6b4ab
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/decorators/is-object.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown> | 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<string, unknown>;
}

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 } }))
);
});
});

Expand Down

0 comments on commit 2d6b4ab

Please sign in to comment.