Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix keys retrieval in objectsEqual function #665

Merged
merged 5 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
});
Loading