Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
}
}
}
}
}
}
},
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);
});
});