Skip to content

Commit 10445df

Browse files
committed
Add tests for object required properties validation
1 parent 5bbaf25 commit 10445df

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

tests/dataValidation.test.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ test('object has all the keys that are in schema', () => {
174174
'b': {'type': 'string'}
175175
}
176176
};
177-
let wrong_data = {'a': ''}; // some meys missing
177+
let wrong_data = {'a': ''}; // some keys missing
178178
let data_1 = {'a': '', 'b': ''}; // exact keys
179179
let data_2 = {'a': '', 'b': '', 'c': ''}; // extra keys
180180
let validator = new DataValidator(schema);
@@ -183,6 +183,19 @@ test('object has all the keys that are in schema', () => {
183183
expect(validator.validate(data_2).isValid).toBe(true);
184184
});
185185

186+
test('object required properties', () => {
187+
let schema = {
188+
'type': 'object',
189+
'properties': {'a': {'type': 'string'}},
190+
'required': ['a'],
191+
};
192+
let wrong_data = {'a': ''}; // empty data
193+
let data = {'a': 'hello'};
194+
let validator = new DataValidator(schema);
195+
expect(validator.validate(wrong_data).isValid).toBe(false);
196+
expect(validator.validate(data).isValid).toBe(true);
197+
});
198+
186199
test('additionalProperties type', () => {
187200
// 1.
188201
let schema = {

0 commit comments

Comments
 (0)