Skip to content

Commit

Permalink
fix: count stripping unknown fields as changes for object casts
Browse files Browse the repository at this point in the history
fixes #1620
  • Loading branch information
jquense committed Aug 20, 2022
1 parent 5e8e8ef commit 2b4773c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,35 @@ describe('Object types', () => {
expect(inst.fields.prop).toBeDefined();
});

describe('stripUnknown', () => {
it('should remove extra fields', () => {
const inst = object({
str: string(),
});

expect(
inst.cast(
{ str: 'hi', extra: false, sneaky: undefined },
{ stripUnknown: true },
),
).toStrictEqual({
str: 'hi',
});
});

it('should one undefined extra fields', () => {
const inst = object({
str: string(),
});

expect(
inst.cast({ str: 'hi', sneaky: undefined }, { stripUnknown: true }),
).toStrictEqual({
str: 'hi',
});
});
});

describe('object defaults', () => {
const createSchema = () =>
object({
Expand Down

0 comments on commit 2b4773c

Please sign in to comment.