@@ -12,37 +12,27 @@ describe('Plotly.downloadImage', function() {
1212 'use strict' ;
1313 var gd ;
1414
15- // override click handler on createElement
16- // so these tests will not actually
17- // download an image each time they are run
18- // full credit goes to @etpinard ; thanks
1915 var createElement = document . createElement ;
20- var msSaveBlob = navigator . msSaveBlob ;
21- var isIE = Lib . isIE ;
2216 var slzProto = ( new window . XMLSerializer ( ) ) . __proto__ ;
2317 var serializeToString = slzProto . serializeToString ;
2418
25- beforeAll ( function ( ) {
26- document . createElement = function ( args ) {
19+ beforeEach ( function ( ) {
20+ gd = createGraphDiv ( ) ;
21+
22+ // override click handler on createElement
23+ // so these tests will not actually
24+ // download an image each time they are run
25+ // full credit goes to @etpinard ; thanks
26+ spyOn ( document , 'createElement' ) . and . callFake ( function ( args ) {
2727 var el = createElement . call ( document , args ) ;
2828 el . click = function ( ) { } ;
2929 return el ;
30- } ;
31- } ) ;
32-
33- afterAll ( function ( ) {
34- document . createElement = createElement ;
35- } ) ;
36-
37- beforeEach ( function ( ) {
38- gd = createGraphDiv ( ) ;
30+ } ) ;
3931 } ) ;
4032
4133 afterEach ( function ( ) {
4234 destroyGraphDiv ( ) ;
43- Lib . isIE = isIE ;
44- slzProto . serializeToString = serializeToString ;
45- navigator . msSaveBlob = msSaveBlob ;
35+ delete navigator . msSaveBlob ;
4636 } ) ;
4737
4838 it ( 'should be attached to Plotly' , function ( ) {
@@ -73,11 +63,11 @@ describe('Plotly.downloadImage', function() {
7363
7464 it ( 'should produce the right SVG output in IE' , function ( done ) {
7565 // mock up IE behavior
76- Lib . isIE = function ( ) { return true ; } ;
77- slzProto . serializeToString = function ( ) {
66+ spyOn ( Lib , 'isIE' ) . and . callFake ( function ( ) { return true ; } ) ;
67+ spyOn ( slzProto , 'serializeToString' ) . and . callFake ( function ( ) {
7868 return serializeToString . apply ( this , arguments )
7969 . replace ( / ( \( # ) ( [ ^ " ) ] * ) ( \) ) / gi, '(\"#$2\")' ) ;
80- } ;
70+ } ) ;
8171 var savedBlob ;
8272 navigator . msSaveBlob = function ( blob ) { savedBlob = blob ; } ;
8373
@@ -96,8 +86,9 @@ describe('Plotly.downloadImage', function() {
9686 } ) ;
9787 } )
9888 . then ( function ( ) {
99- expect ( savedBlob ) . toBeDefined ( ) ;
100- if ( savedBlob === undefined ) return ;
89+ if ( savedBlob === undefined ) {
90+ fail ( 'undefined saveBlob' ) ;
91+ }
10192
10293 return new Promise ( function ( resolve , reject ) {
10394 var reader = new FileReader ( ) ;
0 commit comments