2021-06-22 14:46:42 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
import { assert } from 'chai';
|
|
|
|
|
2021-07-09 19:36:10 +00:00
|
|
|
import { dropNull, shallowDropNull } from '../../util/dropNull';
|
|
|
|
|
|
|
|
type Test = {
|
|
|
|
a: number | null;
|
|
|
|
b: number | undefined;
|
|
|
|
};
|
2021-06-22 14:46:42 +00:00
|
|
|
|
|
|
|
describe('dropNull', () => {
|
|
|
|
it('swaps null with undefined', () => {
|
|
|
|
assert.strictEqual(dropNull(null), undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('leaves undefined be', () => {
|
|
|
|
assert.strictEqual(dropNull(undefined), undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('non-null values undefined be', () => {
|
|
|
|
assert.strictEqual(dropNull('test'), 'test');
|
|
|
|
});
|
2021-07-09 19:36:10 +00:00
|
|
|
|
|
|
|
describe('shallowDropNull', () => {
|
|
|
|
it('return undefined with given null', () => {
|
|
|
|
assert.strictEqual(shallowDropNull<Test>(null), undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('return undefined with given undefined', () => {
|
|
|
|
assert.strictEqual(shallowDropNull<Test>(undefined), undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('swaps null with undefined', () => {
|
|
|
|
const result:
|
|
|
|
| {
|
|
|
|
a: number | undefined;
|
|
|
|
b: number | undefined;
|
|
|
|
}
|
|
|
|
| undefined = shallowDropNull<Test>({
|
|
|
|
a: null,
|
|
|
|
b: 1,
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.deepStrictEqual(result, { a: undefined, b: 1 });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('leaves undefined be', () => {
|
|
|
|
const result:
|
|
|
|
| {
|
|
|
|
a: number | undefined;
|
|
|
|
b: number | undefined;
|
|
|
|
}
|
|
|
|
| undefined = shallowDropNull<Test>({
|
|
|
|
a: 1,
|
|
|
|
b: undefined,
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.deepStrictEqual(result, { a: 1, b: undefined });
|
|
|
|
});
|
|
|
|
});
|
2021-06-22 14:46:42 +00:00
|
|
|
});
|