Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'uniforms-bridge-json-schema' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
}
}
}
}
}
}
}
},
password: { type: 'string', uniforms: { type: 'password' } },
passwordNumeric: { type: 'number', uniforms: { type: 'password' } }
},
required: ['dateOfBirth']
};
const validator = jest.fn();
const bridge = new JSONSchemaBridge(schema, validator);
describe('#constructor()', () => {
it('sets schema correctly when has top level type of object', () => {
expect(bridge.schema).toEqual(schema);
});
it('sets schema correctly when has top level $ref', () => {
const localSchema = {
definitions: schema.definitions,
$ref: '#/definitions/personalData'
};
const localBridge = new JSONSchemaBridge(localSchema, validator);
expect(localBridge.schema).toEqual({
...localSchema,
...localSchema.definitions.personalData
});
it('throws when resolving field schema is not possible', () => {
const localBridge = new JSONSchemaBridge(
{ definitions: schema.definitions, $ref: '#/definitions/personalData' },
validator
);
expect(() => localBridge.getField('invalid')).toThrow(
/Field not found in schema/
);
});
});
it('works on top level when schema does not have properties', () => {
const localBridge = new JSONSchemaBridge(
{ definitions: schema.definitions, $ref: '#/definitions/lastName' },
validator
);
expect(localBridge.getSubfields()).toEqual([]);
});
});
it('falls back to input schema', () => {
const localSchema = { definitions: schema.definitions };
const localBridge = new JSONSchemaBridge(localSchema, validator);
expect(localBridge.schema).toEqual(localSchema);
});
});
it('always returns false', () => {
expect(JSONSchemaBridge.check()).not.toBeTruthy();
expect(JSONSchemaBridge.check(bridge)).not.toBeTruthy();
expect(JSONSchemaBridge.check(schema)).not.toBeTruthy();
expect(JSONSchemaBridge.check(validator)).not.toBeTruthy();
});
});
it('always returns false', () => {
expect(JSONSchemaBridge.check()).not.toBeTruthy();
expect(JSONSchemaBridge.check(bridge)).not.toBeTruthy();
expect(JSONSchemaBridge.check(schema)).not.toBeTruthy();
expect(JSONSchemaBridge.check(validator)).not.toBeTruthy();
});
});
it('always returns false', () => {
expect(JSONSchemaBridge.check()).not.toBeTruthy();
expect(JSONSchemaBridge.check(bridge)).not.toBeTruthy();
expect(JSONSchemaBridge.check(schema)).not.toBeTruthy();
expect(JSONSchemaBridge.check(validator)).not.toBeTruthy();
});
});
it('always returns false', () => {
expect(JSONSchemaBridge.check()).not.toBeTruthy();
expect(JSONSchemaBridge.check(bridge)).not.toBeTruthy();
expect(JSONSchemaBridge.check(schema)).not.toBeTruthy();
expect(JSONSchemaBridge.check(validator)).not.toBeTruthy();
});
});
function createValidator(schema) {
const validator = ajv.compile(schema);
return model => {
validator(model);
if (validator.errors && validator.errors.length) {
throw { details: validator.errors };
}
};
}
const schemaValidator = createValidator(schema);
export default new JSONSchemaBridge(schema, schemaValidator);
function createValidator(schema) {
const validator = ajv.compile(schema);
return model => {
validator(model);
if (validator.errors && validator.errors.length) {
throw { details: validator.errors };
}
};
}
const schemaValidator = createValidator(schema);
export default new JSONSchemaBridge(schema, schemaValidator);