Merge pull request #1524 from Alex-Radu/fix/overlay-is-equal-config

fix(overlays): fix condition in is-equal-config util and add null guard
This commit is contained in:
Thijs Louisse 2021-11-10 11:16:27 +01:00 committed by GitHub
commit cf3b14bce0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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);