Skip to content

Commit bc177c8

Browse files
authored
Merge pull request #787 from plotly/adjust-test
use toEqual
2 parents 9780ab1 + 1c9c6b3 commit bc177c8

File tree

1 file changed

+44
-63
lines changed

1 file changed

+44
-63
lines changed

src/lib/__tests__/sortMenu-test.js

Lines changed: 44 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
import sortMenu from '../sortMenu';
22

3-
function stringify(array) {
4-
let string = '';
5-
array.forEach(obj => {
6-
string += JSON.stringify(obj);
7-
});
8-
return string;
9-
}
10-
113
describe('sortMenu', () => {
124
it('modifies original array to follow the group, then name order provided', () => {
135
const initialArray = [
@@ -17,9 +9,10 @@ describe('sortMenu', () => {
179
const orderProp = [{group: 'DEV', name: 'JSON'}, {group: 'DEV', name: 'Inspector'}];
1810

1911
sortMenu(initialArray, orderProp);
20-
expect(stringify(initialArray)).toBe(
21-
stringify([{props: {group: 'DEV', name: 'JSON'}}, {props: {group: 'DEV', name: 'Inspector'}}])
22-
);
12+
expect(initialArray).toEqual([
13+
{props: {group: 'DEV', name: 'JSON'}},
14+
{props: {group: 'DEV', name: 'Inspector'}},
15+
]);
2316
});
2417

2518
it('sorts the array by group, then by name', () => {
@@ -41,16 +34,14 @@ describe('sortMenu', () => {
4134
];
4235

4336
sortMenu(initialArray, orderProp);
44-
expect(stringify(initialArray)).toBe(
45-
stringify([
46-
{props: {group: 'DEV', name: 'JSON'}},
47-
{props: {group: 'DEV', name: 'Inspector'}},
48-
{props: {group: 'Structure', name: 'Subplots'}},
49-
{props: {group: 'Structure', name: 'Create'}},
50-
{props: {group: 'Style', name: 'Color Bars'}},
51-
{props: {group: 'Style', name: 'Annotation'}},
52-
])
53-
);
37+
expect(initialArray).toEqual([
38+
{props: {group: 'DEV', name: 'JSON'}},
39+
{props: {group: 'DEV', name: 'Inspector'}},
40+
{props: {group: 'Structure', name: 'Subplots'}},
41+
{props: {group: 'Structure', name: 'Create'}},
42+
{props: {group: 'Style', name: 'Color Bars'}},
43+
{props: {group: 'Style', name: 'Annotation'}},
44+
]);
5445
});
5546

5647
it('puts not mentionned panels to the bottom of list and sorts alphabetically', () => {
@@ -70,16 +61,14 @@ describe('sortMenu', () => {
7061
];
7162

7263
sortMenu(initialArray, orderProp);
73-
expect(stringify(initialArray)).toBe(
74-
stringify([
75-
{props: {group: 'Structure', name: 'Subplots'}},
76-
{props: {group: 'Structure', name: 'Create'}},
77-
{props: {group: 'Style', name: 'Color Bars'}},
78-
{props: {group: 'Style', name: 'Annotation'}},
79-
{props: {group: 'DEV', name: 'Inspector'}},
80-
{props: {group: 'DEV', name: 'JSON'}},
81-
])
82-
);
64+
expect(initialArray).toEqual([
65+
{props: {group: 'Structure', name: 'Subplots'}},
66+
{props: {group: 'Structure', name: 'Create'}},
67+
{props: {group: 'Style', name: 'Color Bars'}},
68+
{props: {group: 'Style', name: 'Annotation'}},
69+
{props: {group: 'DEV', name: 'Inspector'}},
70+
{props: {group: 'DEV', name: 'JSON'}},
71+
]);
8372
});
8473

8574
it('orders not mentionned subpanels at the end, alphabetically', () => {
@@ -92,14 +81,12 @@ describe('sortMenu', () => {
9281
const orderProp = [{group: 'Style', name: 'Traces'}];
9382

9483
sortMenu(initialArray, orderProp);
95-
expect(stringify(initialArray)).toBe(
96-
stringify([
97-
{props: {group: 'Style', name: 'Traces'}},
98-
{props: {group: 'Style', name: 'Axes'}},
99-
{props: {group: 'Style', name: 'General'}},
100-
{props: {group: 'Structure', name: 'Create'}},
101-
])
102-
);
84+
expect(initialArray).toEqual([
85+
{props: {group: 'Style', name: 'Traces'}},
86+
{props: {group: 'Style', name: 'Axes'}},
87+
{props: {group: 'Style', name: 'General'}},
88+
{props: {group: 'Structure', name: 'Create'}},
89+
]);
10390
});
10491

10592
it('ignores non existent panel groups', () => {
@@ -118,14 +105,12 @@ describe('sortMenu', () => {
118105
];
119106

120107
sortMenu(initialArray, orderProp);
121-
expect(stringify(initialArray)).toBe(
122-
stringify([
123-
{props: {group: 'Structure', name: 'Create'}},
124-
{props: {group: 'Structure', name: 'Subplots'}},
125-
{props: {group: 'Style', name: 'Color Bars'}},
126-
{props: {group: 'Style', name: 'Annotation'}},
127-
])
128-
);
108+
expect(initialArray).toEqual([
109+
{props: {group: 'Structure', name: 'Create'}},
110+
{props: {group: 'Structure', name: 'Subplots'}},
111+
{props: {group: 'Style', name: 'Color Bars'}},
112+
{props: {group: 'Style', name: 'Annotation'}},
113+
]);
129114
});
130115

131116
it('ignores non existent panel names', () => {
@@ -143,14 +128,12 @@ describe('sortMenu', () => {
143128
];
144129

145130
sortMenu(initialArray, orderProp);
146-
expect(stringify(initialArray)).toBe(
147-
stringify([
148-
{props: {group: 'Style', name: 'Color Bars'}},
149-
{props: {group: 'Style', name: 'Annotation'}},
150-
{props: {group: 'Structure', name: 'Create'}},
151-
{props: {group: 'Structure', name: 'Subplots'}},
152-
])
153-
);
131+
expect(initialArray).toEqual([
132+
{props: {group: 'Style', name: 'Color Bars'}},
133+
{props: {group: 'Style', name: 'Annotation'}},
134+
{props: {group: 'Structure', name: 'Create'}},
135+
{props: {group: 'Structure', name: 'Subplots'}},
136+
]);
154137
});
155138

156139
it('ignores invalid combinations', () => {
@@ -168,13 +151,11 @@ describe('sortMenu', () => {
168151
];
169152

170153
sortMenu(initialArray, orderProp);
171-
expect(stringify(initialArray)).toBe(
172-
stringify([
173-
{props: {group: 'Style', name: 'Color Bars'}},
174-
{props: {group: 'Style', name: 'Annotation'}},
175-
{props: {group: 'Structure', name: 'Create'}},
176-
{props: {group: 'Structure', name: 'Subplots'}},
177-
])
178-
);
154+
expect(initialArray).toEqual([
155+
{props: {group: 'Style', name: 'Color Bars'}},
156+
{props: {group: 'Style', name: 'Annotation'}},
157+
{props: {group: 'Structure', name: 'Create'}},
158+
{props: {group: 'Structure', name: 'Subplots'}},
159+
]);
179160
});
180161
});

0 commit comments

Comments
 (0)