Skip to content

Commit

Permalink
fix(overlays): fix condition in is-equal-config util and add null guard
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Radu committed Nov 10, 2021
1 parent eb61cbf commit b6be7ba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/sour-rules-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lion/overlays': patch
---

fix condition in is-equal-config util and add null guard
2 changes: 1 addition & 1 deletion packages/overlays/src/utils/is-equal-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions packages/overlays/test/utils-tests/is-equal-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b6be7ba

Please sign in to comment.