How to use the yup.ValidationError function in yup

To help you get started, we’ve selected a few yup examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / yup / yup-tests.ts View on Github external
ValidationError.formatError('error');
ValidationError.formatError(() => 'error');
ValidationError.formatError(() => 'error', { path: 'path' });

// ValidationError
let error: ValidationError = new yup.ValidationError('error', 'value', 'path');
error = new yup.ValidationError(['error', 'error2'], true, 'path');
error = new yup.ValidationError(['error', 'error2'], 5, 'path');
error = new yup.ValidationError(['error', 'error2'], { name: 'value' }, 'path');
error = new yup.ValidationError(['error', 'error2'], { name: 'value' }, 'path', 'type');
error = {
    name: 'ValidationError',
    message: 'error',
    path: 'path',
    errors: ['error'],
    inner: [new yup.ValidationError('error', true, 'path')],
    type: 'date',
    value: { start: '2017-11-10' },
};
error.value = 'value';
error.value = true;
error.value = 5;
error.value = { name: 'value' };
error.type = {};
error.type = [];
error.errors = ['error'];

// mixed
let mixed: MixedSchema = yup.mixed();
mixed.clone();
mixed.label('label');
mixed.meta({ meta: 'value' });
github DefinitelyTyped / DefinitelyTyped / types / yup / yup-tests.ts View on Github external
const renderables = yup.array().of(renderable);

// ValidationError static methods
// $ExpectType boolean
ValidationError.isError(new ValidationError('error', 'value', 'path'));
// $ExpectType string | ((params?: any) => string)
ValidationError.formatError('error', { path: 'path' });
ValidationError.formatError('error');
ValidationError.formatError(() => 'error');
ValidationError.formatError(() => 'error', { path: 'path' });

// ValidationError
let error: ValidationError = new yup.ValidationError('error', 'value', 'path');
error = new yup.ValidationError(['error', 'error2'], true, 'path');
error = new yup.ValidationError(['error', 'error2'], 5, 'path');
error = new yup.ValidationError(['error', 'error2'], { name: 'value' }, 'path');
error = new yup.ValidationError(['error', 'error2'], { name: 'value' }, 'path', 'type');
error = {
    name: 'ValidationError',
    message: 'error',
    path: 'path',
    errors: ['error'],
    inner: [new yup.ValidationError('error', true, 'path')],
    type: 'date',
    value: { start: '2017-11-10' },
};
error.value = 'value';
error.value = true;
error.value = 5;
error.value = { name: 'value' };
error.type = {};
error.type = [];
github DefinitelyTyped / DefinitelyTyped / types / yup / yup-tests.ts View on Github external
});
const renderables = yup.array().of(renderable);

// ValidationError static methods
// $ExpectType boolean
ValidationError.isError(new ValidationError('error', 'value', 'path'));
// $ExpectType string | ((params?: any) => string)
ValidationError.formatError('error', { path: 'path' });
ValidationError.formatError('error');
ValidationError.formatError(() => 'error');
ValidationError.formatError(() => 'error', { path: 'path' });

// ValidationError
let error: ValidationError = new yup.ValidationError('error', 'value', 'path');
error = new yup.ValidationError(['error', 'error2'], true, 'path');
error = new yup.ValidationError(['error', 'error2'], 5, 'path');
error = new yup.ValidationError(['error', 'error2'], { name: 'value' }, 'path');
error = new yup.ValidationError(['error', 'error2'], { name: 'value' }, 'path', 'type');
error = {
    name: 'ValidationError',
    message: 'error',
    path: 'path',
    errors: ['error'],
    inner: [new yup.ValidationError('error', true, 'path')],
    type: 'date',
    value: { start: '2017-11-10' },
};
error.value = 'value';
error.value = true;
error.value = 5;
error.value = { name: 'value' };
error.type = {};
github jquense / react-formal / test / Form.spec.js View on Github external
it('return hash of errors from aggregate error', () => {
    Form.toErrors(
      new yup.ValidationError([
        new yup.ValidationError('foo', null, 'bar'),
        new yup.ValidationError('bar', null, 'foo'),
      ])
    ).should.to.eql({
      foo: [{ message: 'bar', values: undefined, type: undefined }],
      bar: [{ message: 'foo', values: undefined, type: undefined }],
    })
  })
github jquense / react-formal / test / form.js View on Github external
it('return hash of errors from a single error', () => {
    Form.toErrors(new yup.ValidationError('hello!', {}, 'path'))
      .should.to.eql({
        'path': [{
          message: 'hello!',
          values: undefined,
          type: undefined
        }]
      });
  })
github jquense / react-formal / test / Form.spec.js View on Github external
it('return hash of errors from aggregate error', () => {
    Form.toErrors(
      new yup.ValidationError([
        new yup.ValidationError('foo', null, 'bar'),
        new yup.ValidationError('bar', null, 'foo'),
      ])
    ).should.to.eql({
      foo: [{ message: 'bar', values: undefined, type: undefined }],
      bar: [{ message: 'foo', values: undefined, type: undefined }],
    })
  })
github jquense / react-formal / test / form.js View on Github external
it('return hash of errors from aggregate error', () => {
    Form.toErrors(new yup.ValidationError([
      new yup.ValidationError('foo', null, 'bar'),
      new yup.ValidationError('bar', null, 'foo')
    ]))
    .should.to.eql({
      'foo': [{ message: 'bar', values: undefined, type: undefined }],
      'bar': [{ message: 'foo', values: undefined, type: undefined }]
    });
  })
github gojek / turing / ui / src / router / components / form / validation / schema.js View on Github external
propertyValue &&
        list.some(
          other => other !== item && get(other, propertyPath) === propertyValue
        )
      ) {
        errors.push(
          this.createError({
            path: `${this.path}[${index}].${propertyPath}`,
            message
          })
        );
      }
    });

    if (errors.length > 0) {
      throw new yup.ValidationError(errors);
    }

    return true;
  });
});
github elifesciences / elife-xpub / packages / component-submission / client / components / steps / Editors / SuggestedReviewersValidator.js View on Github external
throwValidationError = (message, errors) => {
    const parentError = new yup.ValidationError(message)
    parentError.path = 'suggestedReviewers'
    parentError.inner = errors
    throw parentError
  }