diff --git a/__tests__/suits/Area.test.tsx b/__tests__/suits/Area.test.tsx index 08700d9..8de4f76 100644 --- a/__tests__/suits/Area.test.tsx +++ b/__tests__/suits/Area.test.tsx @@ -17,13 +17,30 @@ describe('test ValidatorProvider', () => { return 'not passed'; } }); - Validator.extend('required', required) + Validator.extend('required', required); + + Validator.extend('long_wait', { + async passed(): Promise { + return new Promise((resolve: (value: boolean) => void): void => { + setTimeout(() => { + resolve(true); + }, 100); + }) + }, + message(): string { + return 'test'; + } + }); + }); + + afterEach(() => { + jest.useRealTimers(); }); it('should render input', () => { const area = mount( - + ); @@ -34,7 +51,7 @@ describe('test ValidatorProvider', () => { const area = mount( {() => ( - + )} ); @@ -65,8 +82,8 @@ describe('test ValidatorProvider', () => { <> <>
- - + + <>
@@ -80,7 +97,7 @@ describe('test ValidatorProvider', () => { it('should apply rules on blur', async () => { const area = mount( - + ); @@ -92,7 +109,7 @@ describe('test ValidatorProvider', () => { it('should not apply rules on blur when non-blurrable element', () => { const area = mount( - + ); @@ -103,10 +120,10 @@ describe('test ValidatorProvider', () => { it('should render error when area dirty', async () => { const area = mount( - {({ errors }) => { + {({errors}) => { return ( <> - + {!!errors.length &&
{errors[0]}
} ); @@ -125,7 +142,7 @@ describe('test ValidatorProvider', () => { const area = mount( - + ); @@ -133,6 +150,19 @@ describe('test ValidatorProvider', () => { expect(mockFn).toBeCalled(); }); + it('should call element\'s provided onChange along validator onChange', () => { + const mockFn = jest.fn(); + + const area = mount( + + + + ); + + area.find('input').simulate('change'); + expect(mockFn).toBeCalled(); + }); + it('should get all input refs from the provider', async () => { Validator.extend('test_all', (validator: Validator) => ({ passed(): boolean { @@ -146,15 +176,15 @@ describe('test ValidatorProvider', () => { const provider = mount( - {({ validate }: ProviderScope) => ( + {({validate}: ProviderScope) => ( <> - + - + -