@@ -263,13 +263,7 @@ describe('template interactions', function() {
263
263
264
264
describe ( 'validateTemplate' , function ( ) {
265
265
266
- function checkValidate ( mock , expected , countToCheck ) {
267
- var template = mock . layout . template ;
268
- var mockNoTemplate = Lib . extendDeep ( { } , mock ) ;
269
- delete mockNoTemplate . layout . template ;
270
-
271
- var out1 = Plotly . validateTemplate ( mock ) ;
272
- var out2 = Plotly . validateTemplate ( mockNoTemplate , template ) ;
266
+ function compareOutputs ( out1 , out2 , expected , countToCheck ) {
273
267
expect ( out2 ) . toEqual ( out1 ) ;
274
268
if ( expected ) {
275
269
expect ( countToCheck ? out1 . slice ( 0 , countToCheck ) : out1 )
@@ -280,17 +274,39 @@ describe('validateTemplate', function() {
280
274
}
281
275
}
282
276
277
+ function checkValidate ( mock , expected , countToCheck ) {
278
+ var template = mock . layout . template ;
279
+ var mockNoTemplate = Lib . extendDeep ( { } , mock ) ;
280
+ delete mockNoTemplate . layout . template ;
281
+
282
+ // Test with objects as argument
283
+ var out1 = Plotly . validateTemplate ( mock ) ;
284
+ var out2 = Plotly . validateTemplate ( mockNoTemplate , template ) ;
285
+ expect ( out2 ) . toEqual ( out1 ) ;
286
+ compareOutputs ( out1 , out2 , expected , countToCheck ) ;
287
+
288
+ // Test with DOM elements as argument
289
+ var gd = createGraphDiv ( ) ;
290
+ return Plotly . newPlot ( gd , mock )
291
+ . then ( function ( ) { out1 = Plotly . validateTemplate ( gd ) ; } )
292
+ . then ( function ( ) { return Plotly . newPlot ( gd , mockNoTemplate ) ; } )
293
+ . then ( function ( ) { out2 = Plotly . validateTemplate ( gd , template ) ; } )
294
+ . then ( function ( ) { compareOutputs ( out1 , out2 , expected , countToCheck ) ; } )
295
+ . catch ( failTest )
296
+ . then ( destroyGraphDiv ) ;
297
+ }
298
+
283
299
var cleanMock = Lib . extendDeep ( { } , templateMock ) ;
284
300
cleanMock . layout . annotations . pop ( ) ;
285
301
cleanMock . data . pop ( ) ;
286
302
cleanMock . data . splice ( 1 , 1 ) ;
287
303
cleanMock . layout . template . data . bar . pop ( ) ;
288
304
289
- it ( 'returns undefined when the template matches precisely' , function ( ) {
290
- checkValidate ( cleanMock ) ;
305
+ it ( 'returns undefined when the template matches precisely' , function ( done ) {
306
+ checkValidate ( cleanMock ) . then ( done ) ;
291
307
} ) ;
292
308
293
- it ( 'catches all classes of regular issue' , function ( ) {
309
+ it ( 'catches all classes of regular issue' , function ( done ) {
294
310
var messyMock = Lib . extendDeep ( { } , templateMock ) ;
295
311
messyMock . data . push ( { type : 'box' , x0 : 1 , y : [ 1 , 2 , 3 ] } ) ;
296
312
messyMock . layout . template . layout . geo = { projection : { type : 'orthographic' } } ;
@@ -347,10 +363,10 @@ describe('validateTemplate', function() {
347
363
path : 'layout.annotations[4]' ,
348
364
templateitemname : 'nope' ,
349
365
msg : 'There are no templates for item layout.annotations[4] with name nope'
350
- } ] ) ;
366
+ } ] ) . then ( done ) ;
351
367
} ) ;
352
368
353
- it ( 'catches missing template.data' , function ( ) {
369
+ it ( 'catches missing template.data' , function ( done ) {
354
370
var noDataMock = Lib . extendDeep ( { } , cleanMock ) ;
355
371
delete noDataMock . layout . template . data ;
356
372
@@ -360,17 +376,17 @@ describe('validateTemplate', function() {
360
376
} ] ,
361
377
// check only the first error - we don't care about the specifics
362
378
// uncovered after we already know there's no template.data
363
- 1 ) ;
379
+ 1 ) . then ( done ) ;
364
380
} ) ;
365
381
366
- it ( 'catches missing template.layout' , function ( ) {
382
+ it ( 'catches missing template.layout' , function ( done ) {
367
383
var noLayoutMock = Lib . extendDeep ( { } , cleanMock ) ;
368
384
delete noLayoutMock . layout . template . layout ;
369
385
370
386
checkValidate ( noLayoutMock , [ {
371
387
code : 'layout' ,
372
388
msg : 'The template has no key layout.'
373
- } ] , 1 ) ;
389
+ } ] , 1 ) . then ( done ) ;
374
390
} ) ;
375
391
376
392
} ) ;
0 commit comments