Skip to content

Commit

Permalink
fix: string().notRequired() (#1824)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwassermann authored Nov 7, 2022
1 parent 6250a14 commit dcb4b63
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default class StringSchema<

notRequired() {
return super.notRequired().withMutation((schema: this) => {
schema.tests.filter((t) => t.OPTIONS!.name !== 'required');
schema.tests = schema.tests.filter((t) => t.OPTIONS!.name !== 'required');
return schema;
});
}
Expand Down
9 changes: 9 additions & 0 deletions test/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ describe('String types', () => {
]);
});

it('should handle NOTREQUIRED correctly', function () {
let v = string().required().notRequired();

return Promise.all([
expect(v.isValid(undefined)).resolves.toBe(true),
expect(v.isValid('')).resolves.toBe(true),
]);
});

it('should check MATCHES correctly', function () {
let v = string().matches(/(hi|bye)/, 'A message');

Expand Down

0 comments on commit dcb4b63

Please sign in to comment.