Skip to content

Commit

Permalink
Fix keys retrieval in objectsEqual function (#665)
Browse files Browse the repository at this point in the history
* Fix keys retrieval in objectsEqual function

* added a test case that was actually failing before the fix

---------

Co-authored-by: Constantin Groß <[email protected]>
  • Loading branch information
ralfstx and Connum authored Mar 22, 2024
1 parent fda7e3b commit 6408975
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ function arraysEqual(ar1, ar2) {
function objectsEqual(obj1, obj2) {
const val1 = Object.values(obj1);
const val2 = Object.values(obj2);
const keys1 = Object.values(obj1);
const keys2 = Object.values(obj2);
const keys1 = Object.keys(obj1);
const keys2 = Object.keys(obj2);

return arraysEqual(val1, val2) && arraysEqual(keys1, keys2);
}
Expand Down
18 changes: 18 additions & 0 deletions test/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import assert from 'assert';
import { objectsEqual } from '../src/util.js';

describe('util.js', function() {
describe('objectsEqual', function() {
it('should return true for equal objects', function() {
assert.equal(objectsEqual({}, {}), true);
assert.equal(objectsEqual({ foo: 23 }, { foo: 23 }), true);
});

it('should return false for unequal objects', function() {
assert.equal(objectsEqual({}, { foo: 23 }), false);
assert.equal(objectsEqual({ foo: 23 }, { bar: 23 }), false);
assert.equal(objectsEqual({ foo: 23 }, { bar: 42 }), false);
assert.equal(objectsEqual({ foo: 23, bar: 42 }, { foo: 23 }), false);
});
});
});

0 comments on commit 6408975

Please sign in to comment.