Matchers: handle undefined with Is/Is not null (#38036)

This commit is contained in:
Douglas Thrift 2021-08-19 11:24:01 -07:00 committed by GitHub
parent 5edba603a8
commit d18205ff20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 5 deletions

View File

@ -9,7 +9,7 @@ describe('value null matcher', () => {
fields: [
{
name: 'temp',
values: [23, null, 10],
values: [23, null, 10, undefined],
},
],
}),
@ -35,6 +35,14 @@ describe('value null matcher', () => {
expect(matcher(valueIndex, field, frame, data)).toBeFalsy();
});
it('should match undefined values', () => {
const frame = data[0];
const field = frame.fields[0];
const valueIndex = 3;
expect(matcher(valueIndex, field, frame, data)).toBeTruthy();
});
});
describe('value not null matcher', () => {
@ -43,7 +51,7 @@ describe('value not null matcher', () => {
fields: [
{
name: 'temp',
values: [23, null, 10],
values: [23, null, 10, undefined],
},
],
}),
@ -62,11 +70,19 @@ describe('value not null matcher', () => {
expect(matcher(valueIndex, field, frame, data)).toBeTruthy();
});
it('should match non-null values', () => {
it('should not match null values', () => {
const frame = data[0];
const field = frame.fields[0];
const valueIndex = 1;
expect(matcher(valueIndex, field, frame, data)).toBeFalsy();
});
it('should not match undefined values', () => {
const frame = data[0];
const field = frame.fields[0];
const valueIndex = 3;
expect(matcher(valueIndex, field, frame, data)).toBeFalsy();
});
});

View File

@ -10,7 +10,7 @@ const isNullValueMatcher: ValueMatcherInfo<ValueMatcherOptions> = {
get: () => {
return (valueIndex: number, field: Field) => {
const value = field.values.get(valueIndex);
return value === null;
return value == null;
};
},
getOptionsDisplayText: () => {
@ -27,7 +27,7 @@ const isNotNullValueMatcher: ValueMatcherInfo<ValueMatcherOptions> = {
get: () => {
return (valueIndex: number, field: Field) => {
const value = field.values.get(valueIndex);
return value !== null;
return value != null;
};
},
getOptionsDisplayText: () => {