@coxy/react-validator 3.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/biome.json +4 -2
- package/dist/index.d.mts +32 -42
- package/dist/index.d.ts +32 -42
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/example/example.tsx +21 -25
- package/example/index.html +2 -7
- package/example/tsconfig.json +6 -6
- package/package.json +12 -13
- package/src/context.ts +8 -3
- package/src/custom-errors.test.tsx +73 -0
- package/src/index.test.ts +19 -4
- package/src/index.ts +4 -3
- package/src/rules.test.ts +9 -4
- package/src/rules.ts +14 -14
- package/src/use-validator.test.tsx +1 -2
- package/src/validator-field.test.tsx +34 -3
- package/src/validator-field.tsx +44 -54
- package/src/validator-wrapper.test.tsx +31 -13
- package/src/validator-wrapper.tsx +58 -55
- package/src/validator.test.tsx +10 -0
- package/src/validator.ts +3 -3
- package/src/jest.d.ts +0 -2
package/src/validator.test.tsx
CHANGED
|
@@ -28,3 +28,13 @@ it('check normal add and remove fields', () => {
|
|
|
28
28
|
newFieldSearchPassword = validator.getField('for-remove')
|
|
29
29
|
expect(newFieldSearchPassword === null).toBe(true)
|
|
30
30
|
})
|
|
31
|
+
|
|
32
|
+
it('removeField does nothing when field is not registered', () => {
|
|
33
|
+
const validator = new Validator()
|
|
34
|
+
// create a field-like object that validator doesn't know about
|
|
35
|
+
// import Field from the module is possible, but we can emulate shape using any
|
|
36
|
+
// Should not throw and should not alter state
|
|
37
|
+
// @ts-expect-error.
|
|
38
|
+
expect(() => validator.removeField({})).not.toThrow()
|
|
39
|
+
expect(validator.getField('unknown')).toBe(null)
|
|
40
|
+
})
|
package/src/validator.ts
CHANGED
|
@@ -3,9 +3,9 @@ import type { FieldParams, Validity } from './types'
|
|
|
3
3
|
import type { Value } from './validator-field'
|
|
4
4
|
|
|
5
5
|
export class Field {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
protected rules: ValidatorRules
|
|
7
|
+
protected required: boolean
|
|
8
|
+
protected value: Value
|
|
9
9
|
public id: string | number
|
|
10
10
|
|
|
11
11
|
constructor({ rules, required, value, id }: FieldParams) {
|
package/src/jest.d.ts
DELETED