Comparing version 2.2.2 to 2.2.3
@@ -1,4 +0,4 @@ | ||
import { Rule } from '../rule/Rule'; | ||
import { Validation } from '../types/Validation'; | ||
import { ValidationRuleError, ValidationRuleResult, ValidationRuleSuccess } from '../types/ValidationRule'; | ||
import { Rule } from '../rule'; | ||
import { Validation } from '../types'; | ||
import { ValidationRuleError, ValidationRuleResult, ValidationRuleSuccess } from '../types'; | ||
@@ -5,0 +5,0 @@ export interface FieldOptions { |
import { expect } from 'chai'; | ||
import 'mocha'; | ||
import { createValidationRule } from '..'; | ||
import { StringRule } from '../rule/StringRule'; | ||
import { createValidationRule, isSuccess } from '..'; | ||
import { StringRule } from '../rule'; | ||
import { extractRule } from '../test_helpers/field'; | ||
import { Validation, ValidationError } from '../types/Validation'; | ||
import { Validation, ValidationError } from '../types'; | ||
import { isError } from '../utils'; | ||
@@ -39,3 +39,12 @@ import { StringField } from './StringField'; | ||
}); | ||
it('should not fail if undefined', () => { | ||
const emptyValue: undefined = undefined; | ||
const field: StringField = new StringField() | ||
.addRule((r) => r.maxLength(10)); | ||
const validation: Validation = field.test(emptyValue); | ||
expect(isSuccess(validation)).to.be.true; | ||
}); | ||
}); | ||
}); |
@@ -17,3 +17,3 @@ import { ValidationRuleResult } from '../types/ValidationRule'; | ||
public minLength(min: number): this { | ||
this.addInternalTestFunction((str) => str.length >= min, { | ||
this.addInternalTestFunction((str) => str && str.length >= min, { | ||
title: 'too short', | ||
@@ -26,3 +26,3 @@ description: `must be at least ${min} characters long`, | ||
public maxLength(max: number): this { | ||
this.addInternalTestFunction((str) => str.length <= max, { | ||
this.addInternalTestFunction((str) => !str || str.length <= max, { | ||
title: 'too long', | ||
@@ -29,0 +29,0 @@ description: `must not be longer than ${max} characters long`, |
import { expect } from 'chai'; | ||
import 'mocha'; | ||
import { StringRule } from '../rule/StringRule'; | ||
import { emptyData, emptyFail, truthyTest } from '../test_helpers/rule'; | ||
import { Validation, ValidationError } from '../types/Validation'; | ||
@@ -98,3 +97,11 @@ import { Schema } from './Schema'; | ||
}); | ||
it('should not fail empty or missing fields', () => { | ||
const schema: Schema = new Schema() | ||
.addField('name', (f) => f | ||
.string() | ||
.addRule((r) => r.maxLength(5)), | ||
); | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "mev", | ||
"version": "2.2.2", | ||
"version": "2.2.3", | ||
"description": "Another validator..", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
298652
3422