@@ -100,6 +100,7 @@ describe('fromV2', () => {
100100
101101 expect ( state . validateStatus ) . toBe ( v3 . ValidateStatus . NotValidated )
102102 expect ( state . error ) . toBe ( undefined )
103+ expect ( state . ownError ) . toBe ( undefined )
103104 } )
104105 it ( 'should work well with onChange' , async ( ) => {
105106 const stateV2 = new v2 . FieldState ( '' , defaultDelay )
@@ -109,11 +110,13 @@ describe('fromV2', () => {
109110 await delay ( )
110111 expect ( state . validateStatus ) . toBe ( v3 . ValidateStatus . Validated )
111112 expect ( state . error ) . toBe ( undefined )
113+ expect ( state . ownError ) . toBe ( undefined )
112114
113115 state . onChange ( '' )
114116 await delay ( )
115117 expect ( state . validateStatus ) . toBe ( v3 . ValidateStatus . Validated )
116118 expect ( state . error ) . toBe ( 'empty' )
119+ expect ( state . ownError ) . toBe ( 'empty' )
117120 } )
118121 it ( 'should work well with v2-state onChange' , async ( ) => {
119122 const stateV2 = new v2 . FieldState ( '' , defaultDelay )
@@ -182,6 +185,7 @@ describe('fromV2', () => {
182185 expect ( state . dirty ) . toBe ( false )
183186 expect ( state . validateStatus ) . toBe ( v3 . ValidateStatus . NotValidated )
184187 expect ( state . error ) . toBe ( undefined )
188+ expect ( state . ownError ) . toBe ( undefined )
185189
186190 state . dispose ( )
187191 } )
@@ -202,6 +206,7 @@ describe('fromV2', () => {
202206 await validated
203207 expect ( state . validateStatus ) . toBe ( v3 . ValidateStatus . WontValidate )
204208 expect ( state . error ) . toBe ( undefined )
209+ expect ( state . ownError ) . toBe ( undefined )
205210
206211 state . onChange ( '123' )
207212 await delay ( )
@@ -211,11 +216,13 @@ describe('fromV2', () => {
211216 await delay ( )
212217 expect ( state . validateStatus ) . toBe ( v3 . ValidateStatus . WontValidate )
213218 expect ( state . error ) . toBe ( undefined )
219+ expect ( state . ownError ) . toBe ( undefined )
214220
215221 runInAction ( ( ) => options . disabled = false )
216222 await delay ( )
217223 expect ( state . validateStatus ) . toBe ( v3 . ValidateStatus . Validated )
218224 expect ( state . error ) . toBe ( 'empty' )
225+ expect ( state . ownError ) . toBe ( 'empty' )
219226
220227 state . dispose ( )
221228 } )
@@ -330,6 +337,7 @@ describe('fromV2', () => {
330337
331338 expect ( state . validateStatus ) . toBe ( v3 . ValidateStatus . NotValidated )
332339 expect ( state . error ) . toBe ( undefined )
340+ expect ( state . ownError ) . toBe ( undefined )
333341 } )
334342 it ( 'should work well with onChange' , async ( ) => {
335343 const stateV2 = createV2FormState ( '' )
@@ -339,11 +347,13 @@ describe('fromV2', () => {
339347 await delay ( )
340348 expect ( state . validateStatus ) . toBe ( v3 . ValidateStatus . Validated )
341349 expect ( state . error ) . toBe ( undefined )
350+ expect ( state . ownError ) . toBe ( undefined )
342351
343352 state . onChange ( { foo : '' } )
344353 await delay ( )
345354 expect ( state . validateStatus ) . toBe ( v3 . ValidateStatus . Validated )
346355 expect ( state . error ) . toBe ( 'empty' )
356+ expect ( state . ownError ) . toBe ( 'empty' )
347357 } )
348358 it ( 'should work well with v2-state onChange' , async ( ) => {
349359 const stateV2 = createV2FormState ( '' )
@@ -353,11 +363,13 @@ describe('fromV2', () => {
353363 await delay ( )
354364 expect ( state . validateStatus ) . toBe ( v3 . ValidateStatus . Validated )
355365 expect ( state . error ) . toBe ( undefined )
366+ expect ( state . ownError ) . toBe ( undefined )
356367
357368 stateV2 . $ . foo . onChange ( '' )
358369 await delay ( )
359370 expect ( state . validateStatus ) . toBe ( v3 . ValidateStatus . Validated )
360371 expect ( state . error ) . toBe ( 'empty' )
372+ expect ( state . ownError ) . toBe ( 'empty' )
361373 } )
362374 it ( 'should work well with validate()' , async ( ) => {
363375 const stateV2 = createV2FormState ( '' )
@@ -369,6 +381,7 @@ describe('fromV2', () => {
369381 expect ( stateV2 . error ) . toBe ( 'empty' )
370382 expect ( state . validateStatus ) . toBe ( v3 . ValidateStatus . Validated )
371383 expect ( state . error ) . toBe ( 'empty' )
384+ expect ( state . ownError ) . toBe ( 'empty' )
372385
373386 const validateResult1 = await validateRet1
374387 expect ( validateResult1 . hasError ) . toBe ( true )
@@ -381,6 +394,7 @@ describe('fromV2', () => {
381394 expect ( stateV2 . error ) . toBe ( undefined )
382395 expect ( state . validateStatus ) . toBe ( v3 . ValidateStatus . Validated )
383396 expect ( state . error ) . toBe ( undefined )
397+ expect ( state . ownError ) . toBe ( undefined )
384398
385399 const validateResult2 = await validateRet2
386400 expect ( validateResult2 . hasError ) . toBe ( false )
@@ -403,6 +417,7 @@ describe('fromV2', () => {
403417 expect ( state . dirty ) . toBe ( false )
404418 expect ( state . validateStatus ) . toBe ( v3 . ValidateStatus . NotValidated )
405419 expect ( state . error ) . toBe ( undefined )
420+ expect ( state . ownError ) . toBe ( undefined )
406421
407422 state . dispose ( )
408423 } )
@@ -424,6 +439,7 @@ describe('fromV2', () => {
424439 await validated
425440 expect ( state . validateStatus ) . toBe ( v3 . ValidateStatus . WontValidate )
426441 expect ( state . error ) . toBe ( undefined )
442+ expect ( state . ownError ) . toBe ( undefined )
427443
428444 stateV2 . $ . foo . onChange ( '123' )
429445 await delay ( )
@@ -433,11 +449,13 @@ describe('fromV2', () => {
433449 await delay ( )
434450 expect ( state . validateStatus ) . toBe ( v3 . ValidateStatus . WontValidate )
435451 expect ( state . error ) . toBe ( undefined )
452+ expect ( state . ownError ) . toBe ( undefined )
436453
437454 runInAction ( ( ) => options . disabled = false )
438455 await delay ( )
439456 expect ( state . validateStatus ) . toBe ( v3 . ValidateStatus . Validated )
440457 expect ( state . error ) . toBe ( 'empty' )
458+ expect ( state . ownError ) . toBe ( 'empty' )
441459
442460 state . dispose ( )
443461 } )
@@ -497,6 +515,11 @@ describe('fromV2', () => {
497515 expect ( ( ) => state . withValidator ( ( ) => 'boom' ) ) . toThrowError ( 'Operation not supported.' )
498516 expect ( ( ) => state . disableWhen ( ( ) => true ) ) . toThrowError ( 'Operation not supported.' )
499517 } )
518+ it ( 'should throw with unknown state\'s ownError' , ( ) => {
519+ const stateV2 = new V2DumbState ( '' )
520+ const state = fromV2 ( stateV2 )
521+ expect ( ( ) => state . ownError ) . toThrowError ( 'Operation not supported.' )
522+ } )
500523 it ( 'should throw with unknown validate status' , ( ) => {
501524 const stateV2 = new V2DumbState ( '' )
502525 stateV2 . _validateStatus = - 1
@@ -680,6 +703,7 @@ describe('toV2', () => {
680703 }
681704 value : V
682705 dirty = false
706+ ownError = undefined
683707 error = undefined
684708 activated = false
685709 validateStatus = v3 . ValidateStatus . NotValidated
0 commit comments