@@ -263,13 +263,7 @@ describe('template interactions', function() {
263263
264264describe ( 'validateTemplate' , function ( ) {
265265
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 ) {
273267 expect ( out2 ) . toEqual ( out1 ) ;
274268 if ( expected ) {
275269 expect ( countToCheck ? out1 . slice ( 0 , countToCheck ) : out1 )
@@ -280,17 +274,41 @@ describe('validateTemplate', function() {
280274 }
281275 }
282276
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+
283301 var cleanMock = Lib . extendDeep ( { } , templateMock ) ;
284302 cleanMock . layout . annotations . pop ( ) ;
285303 cleanMock . data . pop ( ) ;
286304 cleanMock . data . splice ( 1 , 1 ) ;
287305 cleanMock . layout . template . data . bar . pop ( ) ;
288306
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 ) ;
291309 } ) ;
292310
293- it ( 'catches all classes of regular issue' , function ( ) {
311+ it ( 'catches all classes of regular issue' , function ( done ) {
294312 var messyMock = Lib . extendDeep ( { } , templateMock ) ;
295313 messyMock . data . push ( { type : 'box' , x0 : 1 , y : [ 1 , 2 , 3 ] } ) ;
296314 messyMock . layout . template . layout . geo = { projection : { type : 'orthographic' } } ;
@@ -347,10 +365,10 @@ describe('validateTemplate', function() {
347365 path : 'layout.annotations[4]' ,
348366 templateitemname : 'nope' ,
349367 msg : 'There are no templates for item layout.annotations[4] with name nope'
350- } ] ) ;
368+ } ] ) . then ( done ) ;
351369 } ) ;
352370
353- it ( 'catches missing template.data' , function ( ) {
371+ it ( 'catches missing template.data' , function ( done ) {
354372 var noDataMock = Lib . extendDeep ( { } , cleanMock ) ;
355373 delete noDataMock . layout . template . data ;
356374
@@ -360,17 +378,17 @@ describe('validateTemplate', function() {
360378 } ] ,
361379 // check only the first error - we don't care about the specifics
362380 // uncovered after we already know there's no template.data
363- 1 ) ;
381+ 1 ) . then ( done ) ;
364382 } ) ;
365383
366- it ( 'catches missing template.layout' , function ( ) {
384+ it ( 'catches missing template.layout' , function ( done ) {
367385 var noLayoutMock = Lib . extendDeep ( { } , cleanMock ) ;
368386 delete noLayoutMock . layout . template . layout ;
369387
370388 checkValidate ( noLayoutMock , [ {
371389 code : 'layout' ,
372390 msg : 'The template has no key layout.'
373- } ] , 1 ) ;
391+ } ] , 1 ) . then ( done ) ;
374392 } ) ;
375393
376394} ) ;
0 commit comments