@@ -133,12 +133,7 @@ describe('Test graph_obj', function () {
133
133
var gd ;
134
134
135
135
beforeEach ( function ( ) {
136
- gd = {
137
- data : [
138
- { 'name' : 'a' } ,
139
- { 'name' : 'b' }
140
- ]
141
- } ;
136
+ gd = { data : [ { 'name' : 'a' } , { 'name' : 'b' } ] } ;
142
137
spyOn ( Plotly , 'redraw' ) ;
143
138
spyOn ( Plotly , 'moveTraces' ) ;
144
139
} ) ;
@@ -147,15 +142,15 @@ describe('Test graph_obj', function () {
147
142
var expected = JSON . parse ( JSON . stringify ( gd ) ) ;
148
143
expect ( function ( ) {
149
144
Plotly . addTraces ( gd , 1 , 2 ) ;
150
- } ) . toThrow ( new Error ( 'all values in traces array must be non-array objects' ) ) ;
145
+ } ) . toThrowError ( Error , 'all values in traces array must be non-array objects' ) ;
151
146
152
147
expect ( function ( ) {
153
148
Plotly . addTraces ( gd , [ { } , 4 ] , 2 ) ;
154
- } ) . toThrow ( new Error ( 'all values in traces array must be non-array objects' ) ) ;
149
+ } ) . toThrowError ( Error , 'all values in traces array must be non-array objects' ) ;
155
150
156
151
expect ( function ( ) {
157
152
Plotly . addTraces ( gd , [ { } , [ ] ] , 2 ) ;
158
- } ) . toThrow ( new Error ( 'all values in traces array must be non-array objects' ) ) ;
153
+ } ) . toThrowError ( Error , 'all values in traces array must be non-array objects' ) ;
159
154
160
155
// make sure we didn't muck with gd.data if things failed!
161
156
expect ( gd ) . toEqual ( expected ) ;
@@ -166,7 +161,7 @@ describe('Test graph_obj', function () {
166
161
167
162
expect ( function ( ) {
168
163
Plotly . addTraces ( gd , [ { } , { } ] , 2 ) ;
169
- } ) . toThrow ( new Error ( 'if indices is specified, traces.length must equal indices.length' ) ) ;
164
+ } ) . toThrowError ( Error , 'if indices is specified, traces.length must equal indices.length' ) ;
170
165
171
166
} ) ;
172
167
@@ -182,59 +177,41 @@ describe('Test graph_obj', function () {
182
177
} ) ;
183
178
184
179
it ( 'should work when newIndices is undefined' , function ( ) {
185
- var expectedData = [
186
- { 'name' : 'a' } ,
187
- { 'name' : 'b' } ,
188
- { 'name' : 'c' } ,
189
- { 'name' : 'd' }
190
- ] ;
191
-
192
180
Plotly . addTraces ( gd , [ { 'name' : 'c' } , { 'name' : 'd' } ] ) ;
193
- expect ( gd . data ) . toEqual ( expectedData ) ;
181
+ expect ( gd . data [ 2 ] . name ) . toBeDefined ( ) ;
182
+ expect ( gd . data [ 2 ] . uid ) . toBeDefined ( ) ;
183
+ expect ( gd . data [ 3 ] . name ) . toBeDefined ( ) ;
184
+ expect ( gd . data [ 3 ] . uid ) . toBeDefined ( ) ;
194
185
expect ( Plotly . redraw ) . toHaveBeenCalled ( ) ;
195
186
expect ( Plotly . moveTraces ) . not . toHaveBeenCalled ( ) ;
196
-
197
187
} ) ;
198
188
199
189
it ( 'should work when newIndices is defined' , function ( ) {
200
- var expectedData = [
201
- { 'name' : 'a' } ,
202
- { 'name' : 'b' } ,
203
- { 'name' : 'c' } ,
204
- { 'name' : 'd' }
205
- ] ;
206
-
207
190
Plotly . addTraces ( gd , [ { 'name' : 'c' } , { 'name' : 'd' } ] , [ 1 , 3 ] ) ;
208
- expect ( gd . data ) . toEqual ( expectedData ) ;
191
+ expect ( gd . data [ 2 ] . name ) . toBeDefined ( ) ;
192
+ expect ( gd . data [ 2 ] . uid ) . toBeDefined ( ) ;
193
+ expect ( gd . data [ 3 ] . name ) . toBeDefined ( ) ;
194
+ expect ( gd . data [ 3 ] . uid ) . toBeDefined ( ) ;
209
195
expect ( Plotly . redraw ) . not . toHaveBeenCalled ( ) ;
210
196
expect ( Plotly . moveTraces ) . toHaveBeenCalledWith ( gd , [ - 2 , - 1 ] , [ 1 , 3 ] ) ;
211
197
212
198
} ) ;
213
199
214
200
it ( 'should work when newIndices has negative indices' , function ( ) {
215
- var expectedData = [
216
- { 'name' : 'a' } ,
217
- { 'name' : 'b' } ,
218
- { 'name' : 'c' } ,
219
- { 'name' : 'd' }
220
- ] ;
221
-
222
201
Plotly . addTraces ( gd , [ { 'name' : 'c' } , { 'name' : 'd' } ] , [ - 3 , - 1 ] ) ;
223
- expect ( gd . data ) . toEqual ( expectedData ) ;
202
+ expect ( gd . data [ 2 ] . name ) . toBeDefined ( ) ;
203
+ expect ( gd . data [ 2 ] . uid ) . toBeDefined ( ) ;
204
+ expect ( gd . data [ 3 ] . name ) . toBeDefined ( ) ;
205
+ expect ( gd . data [ 3 ] . uid ) . toBeDefined ( ) ;
224
206
expect ( Plotly . redraw ) . not . toHaveBeenCalled ( ) ;
225
207
expect ( Plotly . moveTraces ) . toHaveBeenCalledWith ( gd , [ - 2 , - 1 ] , [ - 3 , - 1 ] ) ;
226
208
227
209
} ) ;
228
210
229
211
it ( 'should work when newIndices is an integer' , function ( ) {
230
- var expectedData = [
231
- { 'name' : 'a' } ,
232
- { 'name' : 'b' } ,
233
- { 'name' : 'c' }
234
- ] ;
235
-
236
212
Plotly . addTraces ( gd , { 'name' : 'c' } , 0 ) ;
237
- expect ( gd . data ) . toEqual ( expectedData ) ;
213
+ expect ( gd . data [ 2 ] . name ) . toBeDefined ( ) ;
214
+ expect ( gd . data [ 2 ] . uid ) . toBeDefined ( ) ;
238
215
expect ( Plotly . redraw ) . not . toHaveBeenCalled ( ) ;
239
216
expect ( Plotly . moveTraces ) . toHaveBeenCalledWith ( gd , [ - 1 ] , [ 0 ] ) ;
240
217
0 commit comments