Skip to content

Commit 4da9405

Browse files
committed
Make nested-svg test more strict
1 parent 2b65cba commit 4da9405

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

test/jasmine/tests/snapshot_test.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ describe('Plotly.Snapshot', function() {
150150
});
151151

152152
describe('toSVG', function() {
153-
var gd;
153+
var parser = new DOMParser(),
154+
gd;
154155

155156
beforeEach(function() {
156157
gd = createGraphDiv();
@@ -163,19 +164,21 @@ describe('Plotly.Snapshot', function() {
163164
Plotly.plot(gd, subplotMock.data, subplotMock.layout).then(function() {
164165
return Plotly.Snapshot.toSVG(gd);
165166
}).then(function(svg) {
166-
var splitSVG = svg.split('<svg');
167+
var svgDOM = parser.parseFromString(svg, 'image/svg+xml'),
168+
svgElements = svgDOM.getElementsByTagName('svg');
167169

168-
expect(splitSVG.length).toBe(2);
170+
expect(svgElements.length).toBe(1);
169171
}).then(done);
170172
});
171173

172174
it('should not return any nested svg tags of annotations', function(done) {
173175
Plotly.plot(gd, annotationMock.data, annotationMock.layout).then(function() {
174176
return Plotly.Snapshot.toSVG(gd);
175177
}).then(function(svg) {
176-
var splitSVG = svg.split('<svg');
178+
var svgDOM = parser.parseFromString(svg, 'image/svg+xml'),
179+
svgElements = svgDOM.getElementsByTagName('svg');
177180

178-
expect(splitSVG.length).toBe(2);
181+
expect(svgElements.length).toBe(1);
179182
}).then(done);
180183
});
181184
});

0 commit comments

Comments
 (0)