Permalink
Browse files

Convert tests from jstd to Mocha.

  • Loading branch information...
1 parent 319d036 commit 89fdcedbda6906d90e15d84285c4f6c0b8d96d28 @danvk committed Mar 21, 2015
Showing with 2,257 additions and 2,138 deletions.
  1. +1 −0 .jshintrc
  2. +22 −0 auto_tests/.jshintrc
  3. +1 −1 auto_tests/karma.conf.js
  4. +2 −2 auto_tests/tests/CanvasAssertions.js
  5. +4 −4 auto_tests/tests/Util.js
  6. +51 −49 auto_tests/tests/annotations.js
  7. +73 −71 auto_tests/tests/axis_labels-deprecated.js
  8. +214 −212 auto_tests/tests/axis_labels.js
  9. +148 −146 auto_tests/tests/callback.js
  10. +26 −24 auto_tests/tests/connect_separated_points.js
  11. +59 −57 auto_tests/tests/css.js
  12. +23 −22 auto_tests/tests/custom_bars.js
  13. +41 −39 auto_tests/tests/data_api.js
  14. +13 −11 auto_tests/tests/date_formats.js
  15. +179 −177 auto_tests/tests/date_ticker.js
  16. +27 −26 auto_tests/tests/dygraph-options-tests.js
  17. +32 −30 auto_tests/tests/error_bars.js
  18. +16 −14 auto_tests/tests/fast_canvas_proxy.js
  19. +12 −10 auto_tests/tests/fill_step_plot.js
  20. +25 −23 auto_tests/tests/formats.js
  21. +40 −38 auto_tests/tests/grid_per_axis.js
  22. +11 −9 auto_tests/tests/hidpi.js
  23. +95 −91 auto_tests/tests/interaction_model.js
  24. +54 −52 auto_tests/tests/missing_points.js
  25. +14 −12 auto_tests/tests/multi_csv.js
  26. +48 −46 auto_tests/tests/multiple_axes.js
  27. +19 −17 auto_tests/tests/no_hours.js
  28. +123 −121 auto_tests/tests/numeric_ticker.js
  29. +19 −17 auto_tests/tests/parser.js
  30. +25 −23 auto_tests/tests/pathological_cases.js
  31. +23 −21 auto_tests/tests/per_axis.js
  32. +41 −39 auto_tests/tests/per_series.js
  33. +28 −26 auto_tests/tests/plugins.js
  34. +10 −8 auto_tests/tests/plugins_legend.js
  35. +67 −65 auto_tests/tests/range_selector.js
  36. +87 −84 auto_tests/tests/range_tests.js
  37. +22 −20 auto_tests/tests/resize.js
  38. +67 −65 auto_tests/tests/rolling_average.js
  39. +39 −37 auto_tests/tests/sanity.js
  40. +19 −17 auto_tests/tests/scientific_notation.js
  41. +15 −13 auto_tests/tests/scrolling_div.js
  42. +22 −20 auto_tests/tests/selection.js
  43. +25 −23 auto_tests/tests/simple_drawing.js
  44. +17 −15 auto_tests/tests/smooth_plotter.js
  45. +58 −56 auto_tests/tests/stacked.js
  46. +22 −20 auto_tests/tests/step_plot_per_series.js
  47. +92 −90 auto_tests/tests/to_dom_coords.js
  48. +6 −4 auto_tests/tests/two_digit_years.js
  49. +35 −33 auto_tests/tests/update_options.js
  50. +14 −12 auto_tests/tests/update_while_panning.js
  51. +105 −103 auto_tests/tests/utils_test.js
  52. +23 −21 auto_tests/tests/visibility.js
  53. +3 −2 package.json
View
@@ -8,6 +8,7 @@
"latedef": true,
"nonbsp": true,
"undef": true,
+ "sub": true,
"browser": true,
"devel": true,
View
@@ -0,0 +1,22 @@
+{
+ "extends": "../.jshintrc",
+
+ "asi": true,
+ "mocha": true,
+ "strict": false,
+
+ "laxbreak": true,
+
+ "globals": {
+ "assert": true,
+ "Dygraph": true,
+ "DygraphOps": true,
+ "Util": true,
+ "CanvasAssertions": true,
+ "PixelSampler": true,
+ "smoothPlotter": true,
+ "$": true,
+ "DygraphCanvasRenderer": true,
+ "DygraphOptions": true
+ }
+}
@@ -3,7 +3,7 @@ module.exports = function (config) {
basePath: '../',
frameworks: ['mocha', 'chai', 'chai-as-promised', 'sinon-chai', 'chai-things', 'dirty-chai'],
files: [
- 'auto_tests/**.js',
+ 'auto_tests/**/*.js',
'dist/dygraph-combined.dev.js',
'src/extras/smooth-plotter.js',
],
@@ -115,8 +115,8 @@ CanvasAssertions.assertLineDrawn = function(proxy, p1, p2, predicate) {
}
return s + "}";
};
- fail("Can't find a line drawn between " + p1 +
- " and " + p2 + " with attributes " + toString(predicate));
+ throw "Can't find a line drawn between " + p1 +
+ " and " + p2 + " with attributes " + toString(predicate);
};
/**
@@ -62,9 +62,9 @@ Util.getLegend = function(parent) {
* Assert that all elements have a certain style property.
*/
Util.assertStyleOfChildren = function(selector, property, expectedValue) {
- assertTrue(selector.length > 0);
+ assert.isTrue(selector.length > 0);
$.each(selector, function(idx, child) {
- assertEquals(expectedValue, $(child).css(property));
+ assert.isEqual(expectedValue, $(child).css(property));
});
};
@@ -121,15 +121,15 @@ Util.overrideXMLHttpRequest = function(data) {
this.responseText = data;
};
FakeXMLHttpRequest.restore = function() {
- XMLHttpRequest = originalXMLHttpRequest;
+ window.XMLHttpRequest = originalXMLHttpRequest;
};
FakeXMLHttpRequest.respond = function() {
for (var i = 0; i < requests.length; i++) {
requests[i].onreadystatechange();
}
FakeXMLHttpRequest.restore();
};
- XMLHttpRequest = FakeXMLHttpRequest;
+ window.XMLHttpRequest = FakeXMLHttpRequest;
return FakeXMLHttpRequest;
};
@@ -3,16 +3,16 @@
*
* @author danvk@google.com (Dan Vanderkam)
*/
-var AnnotationsTestCase = TestCase("annotations");
+describe("annotations", function() {
-AnnotationsTestCase.prototype.setUp = function() {
+beforeEach(function() {
document.body.innerHTML = "<div id='graph'></div>";
-};
+});
-AnnotationsTestCase.prototype.tearDown = function() {
-};
+afterEach(function() {
+});
-AnnotationsTestCase.prototype.testAnnotationsDrawn = function() {
+it('testAnnotationsDrawn', function() {
var opts = {
width: 480,
height: 320
@@ -43,23 +43,23 @@ AnnotationsTestCase.prototype.testAnnotationsDrawn = function() {
}
]);
- assertEquals(2, g.annotations().length);
+ assert.equal(2, g.annotations().length);
var a1 = document.getElementsByClassName('ann1');
- assertEquals(1, a1.length);
+ assert.equal(1, a1.length);
a1 = a1[0];
- assertEquals('A', a1.textContent);
+ assert.equal('A', a1.textContent);
var a2 = document.getElementsByClassName('ann2');
- assertEquals(1, a2.length);
+ assert.equal(1, a2.length);
a2 = a2[0];
- assertEquals('B', a2.textContent);
-};
+ assert.equal('B', a2.textContent);
+});
// Some errors that should be flagged:
// 1. Invalid series name (e.g. 'X' or 'non-existent')
// 2. Passing a string as 'x' instead of a number (e.g. x: '1')
-AnnotationsTestCase.prototype.testAnnotationsDontDisappearOnResize = function() {
+it('testAnnotationsDontDisappearOnResize', function() {
var opts = {
};
var data = "X,Y\n" +
@@ -82,23 +82,23 @@ AnnotationsTestCase.prototype.testAnnotationsDontDisappearOnResize = function()
]);
// Check that it displays at all
- assertEquals(1, g.annotations().length);
+ assert.equal(1, g.annotations().length);
var a1 = document.getElementsByClassName('ann1');
- assertEquals(1, a1.length);
+ assert.equal(1, a1.length);
a1 = a1[0];
- assertEquals('A', a1.textContent);
+ assert.equal('A', a1.textContent);
// ... and that resizing doesn't kill it.
g.resize(400, 300);
- assertEquals(1, g.annotations().length);
+ assert.equal(1, g.annotations().length);
var a1 = document.getElementsByClassName('ann1');
- assertEquals(1, a1.length);
+ assert.equal(1, a1.length);
a1 = a1[0];
- assertEquals('A', a1.textContent);
-};
+ assert.equal('A', a1.textContent);
+});
// Verify that annotations outside of the visible x-range are not shown.
-AnnotationsTestCase.prototype.testAnnotationsOutOfRangeX = function() {
+it('testAnnotationsOutOfRangeX', function() {
var opts = {
};
var data = "X,Y\n" +
@@ -121,27 +121,27 @@ AnnotationsTestCase.prototype.testAnnotationsOutOfRangeX = function() {
]);
// Check that it displays at all
- assertEquals(1, g.annotations().length);
+ assert.equal(1, g.annotations().length);
var a1 = document.getElementsByClassName('ann1');
- assertEquals(1, a1.length);
+ assert.equal(1, a1.length);
a1 = a1[0];
- assertEquals('A', a1.textContent);
+ assert.equal('A', a1.textContent);
// ... and that panning right removes the annotation.
g.updateOptions({dateWindow: [2, 6]});
- assertEquals(1, g.annotations().length);
+ assert.equal(1, g.annotations().length);
a1 = document.getElementsByClassName('ann1');
- assertEquals(0, a1.length);
+ assert.equal(0, a1.length);
// ... and that panning left brings it back.
g.updateOptions({dateWindow: [0, 4]});
- assertEquals(1, g.annotations().length);
+ assert.equal(1, g.annotations().length);
a1 = document.getElementsByClassName('ann1');
- assertEquals(1, a1.length);
-};
+ assert.equal(1, a1.length);
+});
// Verify that annotations outside of the visible y-range are not shown.
-AnnotationsTestCase.prototype.testAnnotationsOutOfRangeY = function() {
+it('testAnnotationsOutOfRangeY', function() {
var opts = {
};
var data = "X,Y\n" +
@@ -165,18 +165,18 @@ AnnotationsTestCase.prototype.testAnnotationsOutOfRangeY = function() {
// ... check that panning up removes the annotation.
g.updateOptions({valueRange: [0.5, 2.5]});
- assertEquals(1, g.annotations().length);
- a1 = document.getElementsByClassName('ann1');
- assertEquals(0, a1.length);
+ assert.equal(1, g.annotations().length);
+ var a1 = document.getElementsByClassName('ann1');
+ assert.equal(0, a1.length);
// ... and that panning down brings it back.
g.updateOptions({valueRange: [-1, 1]});
- assertEquals(1, g.annotations().length);
+ assert.equal(1, g.annotations().length);
a1 = document.getElementsByClassName('ann1');
- assertEquals(1, a1.length);
-};
+ assert.equal(1, a1.length);
+});
-AnnotationsTestCase.prototype.testAnnotationsDrawnInDrawCallback = function() {
+it('testAnnotationsDrawnInDrawCallback', function() {
var data = "X,Y\n" +
"0,-1\n" +
"1,0\n" +
@@ -203,13 +203,13 @@ AnnotationsTestCase.prototype.testAnnotationsDrawnInDrawCallback = function() {
}
});
- assertEquals([true, false], calls);
-};
+ assert.deepEqual([true, false], calls);
+});
// Test that annotations on the same point are stacked.
// Regression test for http://code.google.com/p/dygraphs/issues/detail?id=256
-AnnotationsTestCase.prototype.testAnnotationsStacked = function() {
+it('testAnnotationsStacked', function() {
var data = 'X,Y1,Y2\n' +
'0,1,2\n' +
'1,2,3\n';
@@ -235,15 +235,15 @@ AnnotationsTestCase.prototype.testAnnotationsStacked = function() {
g.setAnnotations(annotations);
var annEls = document.getElementsByClassName('dygraphDefaultAnnotation');
- assertEquals(2, annEls.length);
+ assert.equal(2, annEls.length);
- assertEquals(annEls[0].offsetLeft, annEls[1].offsetLeft);
+ assert.equal(annEls[0].offsetLeft, annEls[1].offsetLeft);
assert(annEls[1].offsetTop < annEls[0].offsetTop - 10);
-};
+});
// Test the .ready() method, which is most often used with setAnnotations().
-AnnotationsTestCase.prototype.testReady = function() {
+it('testReady', function() {
var data = 'X,Y1,Y2\n' +
'0,1,2\n' +
'1,2,3\n';
@@ -258,15 +258,17 @@ AnnotationsTestCase.prototype.testReady = function() {
var ready_calls = 0;
g.ready(function() { ready_calls++; });
- assertEquals(0, ready_calls);
+ assert.equal(0, ready_calls);
mockXhr.respond();
- assertEquals(1, ready_calls);
+ assert.equal(1, ready_calls);
// Make sure that ready isn't called on redraws.
g.updateOptions({});
- assertEquals(1, ready_calls);
+ assert.equal(1, ready_calls);
// Or data changes.
g.updateOptions({file: data});
- assertEquals(1, ready_calls);
-};
+ assert.equal(1, ready_calls);
+});
+
+});
Oops, something went wrong.

0 comments on commit 89fdced

Please sign in to comment.