1
- import { Rule } from '../src /Rule' ;
1
+ import { Rule } from '@ /Rule' ;
2
2
import { Validator } from '@/Validator' ;
3
3
4
4
describe ( 'test validator' , ( ) => {
@@ -46,7 +46,7 @@ describe('test validator', () => {
46
46
expect ( Validator . ruleExists ( 'testRule' ) ) . toBeTruthy ( ) ;
47
47
} ) ;
48
48
49
- it ( 'should validate rules as string' , ( ) => {
49
+ it ( 'should validate rules as string' , async ( ) => {
50
50
const input = document . createElement < 'input' > ( 'input' ) ;
51
51
input . value = 'test' ;
52
52
@@ -58,11 +58,11 @@ describe('test validator', () => {
58
58
'test'
59
59
) ;
60
60
61
- validator . validate ( ) ;
61
+ await validator . validate ( ) ;
62
62
expect ( validator . getErrors ( ) . length ) . toBe ( 2 ) ;
63
63
} ) ;
64
64
65
- it ( 'should validate rules as array' , ( ) => {
65
+ it ( 'should validate rules as array' , async ( ) : Promise < void > => {
66
66
const input = document . createElement < 'input' > ( 'input' ) ;
67
67
input . value = 'test' ;
68
68
const validator = new Validator (
@@ -73,11 +73,11 @@ describe('test validator', () => {
73
73
'test'
74
74
) ;
75
75
76
- validator . validate ( ) ;
76
+ await validator . validate ( ) ;
77
77
expect ( validator . getErrors ( ) . length ) . toBe ( 2 ) ;
78
78
} ) ;
79
79
80
- it ( 'should validate with parameters' , ( ) => {
80
+ it ( 'should validate with parameters' , async ( ) : Promise < void > => {
81
81
const input = document . createElement < 'input' > ( 'input' ) ;
82
82
input . value = 'test' ;
83
83
@@ -89,25 +89,22 @@ describe('test validator', () => {
89
89
'test'
90
90
) ;
91
91
92
- validator . validate ( ) ;
92
+ await validator . validate ( ) ;
93
93
expect ( validator . getErrors ( ) [ 0 ] ) . toBe ( 'Rule params not passed: 1, 2, 3, 4' ) ;
94
94
} ) ;
95
95
96
- it ( 'throws an exception when rule is not found' , ( ) => {
96
+ it ( 'throws an exception when rule is not found' , async ( ) : Promise < void > => {
97
97
const input = document . createElement < 'input' > ( 'input' ) ;
98
98
input . value = 'test' ;
99
- const throws = ( ) => {
100
- const validator = new Validator (
101
- [
102
- input
103
- ] ,
104
- [ 'not_existing_rule' ] ,
105
- 'test'
106
- ) ;
107
- validator . validate ( ) ;
108
- }
99
+ const validator = new Validator (
100
+ [
101
+ input
102
+ ] ,
103
+ [ 'not_existing_rule' ] ,
104
+ 'test'
105
+ ) ;
109
106
110
- expect ( ( ) => throws ( ) ) . toThrowError ( 'Validation rule not_existing_rule not found.' ) ;
107
+ await expect ( validator . validate ( ) ) . rejects . toThrowError ( 'Validation rule not_existing_rule not found.' ) ;
111
108
} ) ;
112
109
113
110
it ( 'should merge rules' , ( ) => {
@@ -130,7 +127,7 @@ describe('test validator', () => {
130
127
expect ( ( ) => throws ( ) ) . toThrowError ( 'Areas are only available when validating React components.' )
131
128
} ) ;
132
129
133
- it ( 'should be able to check if the value is required' , ( ) => {
130
+ it ( 'should be able to check if the value is required' , async ( ) => {
134
131
const input = document . createElement < 'input' > ( 'input' ) ;
135
132
input . value = 'test' ;
136
133
Validator . extend ( 'check_if_required' , ( validator : Validator ) => ( {
@@ -150,12 +147,8 @@ describe('test validator', () => {
150
147
'test'
151
148
) ;
152
149
153
- validator . validate ( ) ;
150
+ await validator . validate ( ) ;
154
151
155
152
expect ( validator . getErrors ( ) [ 0 ] ) . toBe ( 'Value is false negative required' ) ;
156
153
} )
157
-
158
- it ( 'should return empty array when no refs provided' , ( ) => {
159
-
160
- } )
161
154
} ) ;
0 commit comments