@@ -12,37 +12,27 @@ describe('Plotly.downloadImage', function() {
12
12
'use strict' ;
13
13
var gd ;
14
14
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
19
15
var createElement = document . createElement ;
20
- var msSaveBlob = navigator . msSaveBlob ;
21
- var isIE = Lib . isIE ;
22
16
var slzProto = ( new window . XMLSerializer ( ) ) . __proto__ ;
23
17
var serializeToString = slzProto . serializeToString ;
24
18
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 ) {
27
27
var el = createElement . call ( document , args ) ;
28
28
el . click = function ( ) { } ;
29
29
return el ;
30
- } ;
31
- } ) ;
32
-
33
- afterAll ( function ( ) {
34
- document . createElement = createElement ;
35
- } ) ;
36
-
37
- beforeEach ( function ( ) {
38
- gd = createGraphDiv ( ) ;
30
+ } ) ;
39
31
} ) ;
40
32
41
33
afterEach ( function ( ) {
42
34
destroyGraphDiv ( ) ;
43
- Lib . isIE = isIE ;
44
- slzProto . serializeToString = serializeToString ;
45
- navigator . msSaveBlob = msSaveBlob ;
35
+ delete navigator . msSaveBlob ;
46
36
} ) ;
47
37
48
38
it ( 'should be attached to Plotly' , function ( ) {
@@ -73,11 +63,11 @@ describe('Plotly.downloadImage', function() {
73
63
74
64
it ( 'should produce the right SVG output in IE' , function ( done ) {
75
65
// 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 ( ) {
78
68
return serializeToString . apply ( this , arguments )
79
69
. replace ( / ( \( # ) ( [ ^ " ) ] * ) ( \) ) / gi, '(\"#$2\")' ) ;
80
- } ;
70
+ } ) ;
81
71
var savedBlob ;
82
72
navigator . msSaveBlob = function ( blob ) { savedBlob = blob ; } ;
83
73
@@ -96,8 +86,9 @@ describe('Plotly.downloadImage', function() {
96
86
} ) ;
97
87
} )
98
88
. then ( function ( ) {
99
- expect ( savedBlob ) . toBeDefined ( ) ;
100
- if ( savedBlob === undefined ) return ;
89
+ if ( savedBlob === undefined ) {
90
+ fail ( 'undefined saveBlob' ) ;
91
+ }
101
92
102
93
return new Promise ( function ( resolve , reject ) {
103
94
var reader = new FileReader ( ) ;
0 commit comments