Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

208
Vistas
Possible to have `validate` fail on not specified elements?

The below returns success, even though obj contains an element that is not in the schema.

Question

Is it possible to have validate fail, when it sees elements that are not specified in the schema?

Jest have this expect(obj1).toEqual(obj2).

If Validate can't do it, what options do I then have to detect unwanted elements?

const Schema = require("validate");

const obj = {good: "1", bad: "2"};

const user = new Schema({
  good: {
    type: String,
    required: true,
  }
});

const r = user.validate(obj);
console.log(r);
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Yes, there is a strict option on the Schema, from the documentation:

Schema

A Schema defines the structure that objects should be validated against.

Parameters
  • obj schema definition
  • opts options
    • opts.typecast

    • opts.strip

    • opts.strict

      Validation fails when object contains properties not defined in the schema (optional, default false)

So you'll need something like:

const options = { strict: true };

const user = new Schema({
  good: {
    type: String,
    required: true,
  }
}, options);
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda