MCPcopy Create free account
hub / github.com/Automattic/mongoose / getCastErrorPath

Function getCastErrorPath

test/types.array.test.js:2279–2286  ·  view source on GitHub ↗
(Model, value)

Source from the content-addressed store, hash-verified

2277 describe('`castNonArrays` on nested arrays', function() {
2278 // Returns the path of the single CastError that `value` causes on `matrix`
2279 async function getCastErrorPath(Model, value) {
2280 const err = await new Model({ matrix: value }).validate().then(() => null, err => err);
2281 assert.ok(err, `expected ${JSON.stringify(value)} to fail casting`);
2282 const paths = Object.keys(err.errors);
2283 assert.equal(paths.length, 1);
2284 assert.equal(err.errors[paths[0]].name, 'CastError');
2285 return paths[0];
2286 }
2287
2288 async function castMatrix(Model, value) {
2289 const doc = new Model({ matrix: value });

Callers 1

Calls 1

validateMethod · 0.80

Tested by

no test coverage detected