Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix expect(new Array(1)).toEqual([undefined]) failures on *some* platforms #1048

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

Merged
merged 4 commits into from
Oct 17, 2016
Merged
Changes from 1 commit
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
53 changes: 40 additions & 13 deletions 53 test/jasmine/tests/lib_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,33 @@ var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var Plots = PlotlyInternal.Plots;

/* This is a one-off function to fully populate sparse arrays. This arises
* because:
*
* var x = new Array(2)
* expect(x).toEqual([undefined, undefined])
*
* will fail assertion even though x[0] === undefined and x[1] === undefined.
* This is because the array elements don't exist until assigned.
*/
function populateUndefinedArrayEls(x) {
var i;
if(Array.isArray(x)) {
for(i = 0; i < x.length; i++) {
x[i] = x[i];
Copy link
Contributor Author

@rreusser rreusser Oct 17, 2016

Choose a reason for hiding this comment

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

😐

}
} else if(Lib.isPlainObject(x)) {
var keys = Object.keys(x);
for(i = 0; i < keys.length; i++) {
populateUndefinedArrayEls(x[keys[i]]);
}
}
}

function expectLooseDeepEqual(a, b) {
expect(populateUndefinedArrayEls(a)).toEqual(populateUndefinedArrayEls(b));
}


describe('Test lib.js:', function() {
'use strict';
Expand Down Expand Up @@ -485,37 +512,37 @@ describe('Test lib.js:', function() {
it('unpacks top-level paths', function() {
var input = {'marker.color': 'red', 'marker.size': [1, 2, 3]};
var expected = {marker: {color: 'red', size: [1, 2, 3]}};
expect(Lib.expandObjectPaths(input)).toEqual(expected);
expectLooseDeepEqual(Lib.expandObjectPaths(input), expected);
});

it('unpacks recursively', function() {
var input = {'marker.color': {'red.certainty': 'definitely'}};
var expected = {marker: {color: {red: {certainty: 'definitely'}}}};
expect(Lib.expandObjectPaths(input)).toEqual(expected);
expectLooseDeepEqual(Lib.expandObjectPaths(input), expected);
});

it('unpacks deep paths', function() {
var input = {'foo.bar.baz': 'red'};
var expected = {foo: {bar: {baz: 'red'}}};
expect(Lib.expandObjectPaths(input)).toEqual(expected);
expectLooseDeepEqual(Lib.expandObjectPaths(input), expected);
});

it('unpacks non-top-level deep paths', function() {
var input = {color: {'foo.bar.baz': 'red'}};
var expected = {color: {foo: {bar: {baz: 'red'}}}};
expect(Lib.expandObjectPaths(input)).toEqual(expected);
expectLooseDeepEqual(Lib.expandObjectPaths(input), expected);
});

it('merges dotted properties into objects', function() {
var input = {marker: {color: 'red'}, 'marker.size': 8};
var expected = {marker: {color: 'red', size: 8}};
expect(Lib.expandObjectPaths(input)).toEqual(expected);
expectLooseDeepEqual(Lib.expandObjectPaths(input), expected);
});

it('merges objects into dotted properties', function() {
var input = {'marker.size': 8, marker: {color: 'red'}};
var expected = {marker: {color: 'red', size: 8}};
expect(Lib.expandObjectPaths(input)).toEqual(expected);
expectLooseDeepEqual(Lib.expandObjectPaths(input), expected);
});

it('retains the identity of nested objects', function() {
Expand All @@ -541,49 +568,49 @@ describe('Test lib.js:', function() {
it('expands bracketed array notation', function() {
var input = {'marker[1]': {color: 'red'}};
var expected = {marker: [undefined, {color: 'red'}]};
expect(Lib.expandObjectPaths(input)).toEqual(expected);
expectLooseDeepEqual(Lib.expandObjectPaths(input), expected);
});

it('expands nested arrays', function() {
var input = {'marker[1].range[1]': 5};
var expected = {marker: [undefined, {range: [undefined, 5]}]};
var computed = Lib.expandObjectPaths(input);
expect(computed).toEqual(expected);
expectLooseDeepEqual(computed, expected);
});

it('expands bracketed array with more nested attributes', function() {
var input = {'marker[1]': {'color.alpha': 2}};
var expected = {marker: [undefined, {color: {alpha: 2}}]};
var computed = Lib.expandObjectPaths(input);
expect(computed).toEqual(expected);
expectLooseDeepEqual(computed, expected);
});

it('expands bracketed array notation without further nesting', function() {
var input = {'marker[1]': 8};
var expected = {marker: [undefined, 8]};
var computed = Lib.expandObjectPaths(input);
expect(computed).toEqual(expected);
expectLooseDeepEqual(computed, expected);
});

it('expands bracketed array notation with further nesting', function() {
var input = {'marker[1].size': 8};
var expected = {marker: [undefined, {size: 8}]};
var computed = Lib.expandObjectPaths(input);
expect(computed).toEqual(expected);
expectLooseDeepEqual(computed, expected);
});

it('expands bracketed array notation with further nesting', function() {
var input = {'marker[1].size.magnitude': 8};
var expected = {marker: [undefined, {size: {magnitude: 8}}]};
var computed = Lib.expandObjectPaths(input);
expect(computed).toEqual(expected);
expectLooseDeepEqual(computed, expected);
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of that custom assert routine, why not just have to expect statements:

expect(computed.marker[0]).toBeUndefined();
expect(computed.marker[1]).toEqual({ size: { magnitude: 8 } });

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 can move the function inside this block, but ideally wanted to avoid manually digging through the objects.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that make sense.

What about moving your new expectLooseDeepEqual to assets/custom_matchers.js ?

});

it('combines changes with single array nesting', function() {
var input = {'marker[1].foo': 5, 'marker[0].foo': 4};
var expected = {marker: [{foo: 4}, {foo: 5}]};
var computed = Lib.expandObjectPaths(input);
expect(computed).toEqual(expected);
expectLooseDeepEqual(computed, expected);
});

// TODO: This test is unimplemented since it's a currently-unused corner case.
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.