fix(overlays): fix condition in is-equal-config util and add null guard

This commit is contained in:
Alex Radu 2021-11-04 14:19:10 +02:00
parent eb61cbfed2
commit b6be7ba482
3 changed files with 18 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'@lion/overlays': patch
---
fix condition in is-equal-config util and add null guard

View file

@ -11,7 +11,7 @@
* @returns {boolean} Whether the configs are equivalent
*/
export function isEqualConfig(a, b) {
if (typeof a !== 'object' || typeof a !== 'object') {
if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) {
return a === b;
}
const aProps = Object.keys(a);

View file

@ -23,6 +23,18 @@ describe('isEqualConfig()', () => {
expect(isEqualConfig(config, config)).eql(true);
});
it('compares null props', () => {
const config = TestConfig();
const nullPropConfig = {
...config,
elementToFocusAfterHide: {
nullProp: null,
},
};
// @ts-ignore
expect(isEqualConfig(nullPropConfig, nullPropConfig)).eql(true);
});
it('compares shallow props', () => {
const config = TestConfig();
expect(isEqualConfig(config, { ...config })).eql(true);