Skip to content

Commit 870e1ce

Browse files
committed
abstract load script for mathjax tests
1 parent 7677258 commit 870e1ce

File tree

2 files changed

+36
-37
lines changed

2 files changed

+36
-37
lines changed

test/jasmine/bundle_tests/mathjax_v2_test.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,27 @@ var d3Select = require('../../strict-d3').select;
44
var createGraphDiv = require('../assets/create_graph_div');
55
var destroyGraphDiv = require('../assets/destroy_graph_div');
66

7+
// N.B. we have to load MathJax "dynamically" as Karam
8+
// does not undefined the MathJax's `?config=` parameter.
9+
//
10+
// Now with the mathjax_config no longer needed,
11+
// it might be nice to move these tests in the "regular" test
12+
// suites, but to do that we'll need to find a way to remove MathJax from
13+
// page without breaking things downstream.
14+
15+
function loadScript(src, done) {
16+
var newScript;
17+
newScript = document.createElement('script');
18+
newScript.src = src;
19+
newScript.type = 'text/javascript';
20+
newScript.onload = done;
21+
newScript.onerror = done.fail;
22+
document.body.appendChild(newScript);
23+
}
724

825
describe('Test MathJax v2:', function() {
9-
var mathJaxScriptTag;
10-
11-
// N.B. we have to load MathJax "dynamically" as Karam
12-
// does not undefined the MathJax's `?config=` parameter.
13-
//
14-
// Now with the mathjax_config no longer needed,
15-
// it might be nice to move these tests in the "regular" test
16-
// suites, but to do that we'll need to find a way to remove MathJax from
17-
// page without breaking things downstream.
1826
beforeAll(function(done) {
19-
mathJaxScriptTag = document.createElement('script');
20-
mathJaxScriptTag.type = 'text/javascript';
21-
mathJaxScriptTag.onload = function() {
22-
done();
23-
};
24-
mathJaxScriptTag.onerror = function() {
25-
fail('MathJax v2 failed to load');
26-
};
27-
mathJaxScriptTag.src = '/base/node_modules/mathjax-v2/MathJax.js?config=TeX-AMS-MML_SVG';
28-
document.body.appendChild(mathJaxScriptTag);
27+
loadScript('/base/node_modules/mathjax-v2/MathJax.js?config=TeX-AMS-MML_SVG', done);
2928
});
3029

3130
describe('Test axis title scoot:', function() {

test/jasmine/bundle_tests/mathjax_v3_test.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@ var d3Select = require('../../strict-d3').select;
44
var createGraphDiv = require('../assets/create_graph_div');
55
var destroyGraphDiv = require('../assets/destroy_graph_div');
66

7+
// TODO: find a better way reuse the code from mathjav v2 tests
8+
//
9+
//
10+
// Now with the mathjax_config no longer needed,
11+
// it might be nice to move these tests in the "regular" test
12+
// suites, but to do that we'll need to find a way to remove MathJax from
13+
// page without breaking things downstream.
14+
15+
function loadScript(src, done) {
16+
var newScript;
17+
newScript = document.createElement('script');
18+
newScript.src = src;
19+
newScript.type = 'text/javascript';
20+
newScript.onload = done;
21+
newScript.onerror = done.fail;
22+
document.body.appendChild(newScript);
23+
}
724

825
describe('Test MathJax v3:', function() {
9-
var mathJaxScriptTag;
10-
11-
// TODO: find a better way reuse the code from mathjav v2 tests
12-
//
13-
// Now with the mathjax_config no longer needed,
14-
// it might be nice to move these tests in the "regular" test
15-
// suites, but to do that we'll need to find a way to remove MathJax from
16-
// page without breaking things downstream.
1726
beforeAll(function(done) {
18-
mathJaxScriptTag = document.createElement('script');
19-
mathJaxScriptTag.type = 'text/javascript';
20-
mathJaxScriptTag.onload = function() {
21-
done();
22-
};
23-
mathJaxScriptTag.onerror = function() {
24-
fail('MathJax v3 failed to load');
25-
};
26-
mathJaxScriptTag.src = '/base/node_modules/mathjax-v3/es5/tex-svg.js';
27-
document.body.appendChild(mathJaxScriptTag);
27+
loadScript('/base/node_modules/mathjax-v3/es5/tex-svg.js', done);
2828
});
2929

3030
describe('Test axis title scoot:', function() {

0 commit comments

Comments
 (0)