Skip to content
Merged
64 changes: 64 additions & 0 deletions test/jasmine/tests/plot_api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3143,6 +3143,70 @@ describe('plot_api helpers', function () {
)
).toBe(true);
});

it('Returns false for null values', () => {
expect(helpers.collectionsAreEqual(null, null)).toBe(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make sense for this case to return true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose, but that's not how the function is supposed to be used. It would require an additional branch to the conditional check and I didn't feel like adding that. If you feel strongly about it, I'll add it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah I don't feel strongly about it. My only suggestion would be to note these details in the function docstring.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSDoc param specs show the args should be an array or object. Do you think more would be necessary?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah my bad I skimmed over the jsdoc, if that conventionally means null is not a valid input I'm satisfied 👍

});

it('Returns false when comparing null and object', () => {
expect(helpers.collectionsAreEqual(null, {})).toBe(false);
});

it('Returns true for empty objects', () => {
expect(helpers.collectionsAreEqual({}, {})).toBe(true);
});

it('Returns true for empty arrays', () => {
expect(helpers.collectionsAreEqual([], [])).toBe(true);
});

it('Returns false for different array lengths', () => {
expect(helpers.collectionsAreEqual([1, 2], [1, 2, 3])).toBe(false);
});

it('Handles underscore keys in nested objects', () => {
expect(
helpers.collectionsAreEqual(
{ level1: { _private: 'a', public: 'b' } },
{ level1: { _private: 'z', public: 'b' } }
)
).toBe(true);
});

it('Returns false when comparing undefined and object', () => {
expect(helpers.collectionsAreEqual(undefined, {})).toBe(false);
});

it('Returns false for objects with different number of keys', () => {
expect(helpers.collectionsAreEqual({ a: 1, b: 2 }, { a: 1 })).toBe(false);
});

it('Returns false when comparing object and array', () => {
expect(helpers.collectionsAreEqual({}, [])).toBe(false);
});

it('Handles objects with array values', () => {
expect(helpers.collectionsAreEqual({ crew: ['Leela', 'Fry'] }, { crew: ['Leela', 'Fry'] })).toBe(true);
});

it('Returns false for objects with different array values', () => {
expect(helpers.collectionsAreEqual({ crew: ['Leela', 'Fry'] }, { crew: ['Leela', 'Bender'] })).toBe(false);
});

it('Handles arrays with object elements', () => {
expect(
helpers.collectionsAreEqual([{ name: 'Leela' }, { name: 'Fry' }], [{ name: 'Leela' }, { name: 'Fry' }])
).toBe(true);
});

it('Returns false for arrays with different object elements', () => {
expect(
helpers.collectionsAreEqual(
[{ name: 'Leela' }, { name: 'Fry' }],
[{ name: 'Leela' }, { name: 'Bender' }]
)
).toBe(false);
});
});
});

Expand Down