import { ErrorKeyKind, Validation } from '../../src';
import { Validator } from '../../src';
import { Parser } from '../../src/parser/parser';

describe('Validator', () => {
  // @note custom validation tested by importAndAdaptAndValidate
  it('Should be able to extend validation error text', () => {
    expect.assertions(3); // 2 errors
    const getErrorText: Validation.GetErrorTextFn = jest.fn(
      (entry, render): string => {
        expect(entry.errorType).toEqual(ErrorKeyKind.EmptyInput);
        return entry.errorType!;
      }
    );

    const parser = new Parser().setText('').parse();
    const { errors } = new Validator({
      getErrorText,
    }).validate(parser);
    expect(errors).toHaveLength(2);
  });

  it('Should have options as optional', () => {
    expect(() => new Validator()).not.toThrow();
  });
});
