diff --git a/src/string.ts b/src/string.ts index 1cde8d422..beceeb379 100644 --- a/src/string.ts +++ b/src/string.ts @@ -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; }); } diff --git a/test/string.ts b/test/string.ts index 2e7f32248..ab0ad3e66 100644 --- a/test/string.ts +++ b/test/string.ts @@ -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');