-
Notifications
You must be signed in to change notification settings - Fork 8
Optional enum fields in type structs don't handle null values properly #71
Copy link
Copy link
Open
Description
When an enum field in struct is made {required: false} and the value for it is set to null the null stays even if there is a default value. If there isn't a default value the null replaces undefined and the enum value is later written as null in the JSON (instead of missing from the result).
Example test:
it.('allows complex type definition (optional non-default enums)', function() {
api.enum('TestEnum', {A: 1, B: 2});
api.type('Test', {
notRequiredDefault: {
type: 'TestEnum',
required: false,
default: 1,
},
notRequiredNoDefault: {
type: 'TestEnum',
required: false
}
});
const testType = api.type('Test');
expect(testType.convert({
notRequiredDefault: null,
notRequiredNoDefault: null
})).to.deep.eq({
notRequiredDefault: 1,
notRequiredNoDefault: undefined
});
});and the failure:
AssertionError: expected { Object (notRequiredDefault, notRequiredNoDefault) } to deeply equal { Object (notRequiredDefault, notRequiredNoDefault) }
+ expected - actual
{
- "notRequiredDefault": [null]
- "notRequiredNoDefault": [null]
+ "notRequiredDefault": 1
+ "notRequiredNoDefault": [undefined]
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels