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