| 1 | import AJV6Validator from '../src/validator'; |
| 2 | import defaultValidator, { customizeValidator } from '../src'; |
| 3 | import { CUSTOM_OPTIONS } from './createAjvInstance.test'; |
| 4 | |
| 5 | jest.mock('../src/validator'); |
| 6 | |
| 7 | type TestType = { |
| 8 | foo: string; |
| 9 | bar: boolean; |
| 10 | }; |
| 11 | |
| 12 | describe('customizeValidator()', () => { |
| 13 | it('defaultValidator was created', () => { |
| 14 | expect(defaultValidator).toBeInstanceOf(AJV6Validator); |
| 15 | }); |
| 16 | it('defaultValidator was constructed with empty object', () => { |
| 17 | expect(AJV6Validator).toHaveBeenCalledWith({}); |
| 18 | }); |
| 19 | describe('passing options to customizeValidator', () => { |
| 20 | let custom: any; |
| 21 | beforeAll(() => { |
| 22 | (AJV6Validator as unknown as jest.Mock).mockClear(); |
| 23 | custom = customizeValidator<TestType>(CUSTOM_OPTIONS); |
| 24 | }); |
| 25 | it('custom validator was created', () => { |
| 26 | expect(custom).toBeInstanceOf(AJV6Validator); |
| 27 | }); |
| 28 | it('defaultValidator was constructed with custom options object', () => { |
| 29 | expect(AJV6Validator).toHaveBeenCalledWith(CUSTOM_OPTIONS); |
| 30 | }); |
| 31 | }); |
| 32 | }); |