Skip to content

Commit dcb4b63

Browse files
authored
fix: string().notRequired() (#1824)
1 parent 6250a14 commit dcb4b63

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/string.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default class StringSchema<
9797

9898
notRequired() {
9999
return super.notRequired().withMutation((schema: this) => {
100-
schema.tests.filter((t) => t.OPTIONS!.name !== 'required');
100+
schema.tests = schema.tests.filter((t) => t.OPTIONS!.name !== 'required');
101101
return schema;
102102
});
103103
}

test/string.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ describe('String types', () => {
9494
]);
9595
});
9696

97+
it('should handle NOTREQUIRED correctly', function () {
98+
let v = string().required().notRequired();
99+
100+
return Promise.all([
101+
expect(v.isValid(undefined)).resolves.toBe(true),
102+
expect(v.isValid('')).resolves.toBe(true),
103+
]);
104+
});
105+
97106
it('should check MATCHES correctly', function () {
98107
let v = string().matches(/(hi|bye)/, 'A message');
99108

0 commit comments

Comments
 (0)