From 5db9ad5da775ff73aa8d859c334935d01f01b930 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Sat, 28 Mar 2015 14:31:57 -0400 Subject: [PATCH] Test non-existent divs --- auto_tests/tests/pathological_cases.js | 14 ++++++++++++++ src/dygraph.js | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/auto_tests/tests/pathological_cases.js b/auto_tests/tests/pathological_cases.js index ade714c..40e877f 100644 --- a/auto_tests/tests/pathological_cases.js +++ b/auto_tests/tests/pathological_cases.js @@ -160,4 +160,18 @@ it('testConstantSeriesNegativeIncludeZero', function() { assert.deepEqual([-1.1, 0], g.yAxisRange()); }); +it('should throw with non-existent divs', function() { + var data = "X,Y\n" + + "1,-1\n" + + "2,1\n"; + + assert.throws(function() { + new Dygraph(null, data); + }, /non-existent div/); + + assert.throws(function() { + new Dygraph('non-existent-div-id', data); + }, /non-existent div/); +}); + }); diff --git a/src/dygraph.js b/src/dygraph.js index 7121458..735ddca 100644 --- a/src/dygraph.js +++ b/src/dygraph.js @@ -403,7 +403,7 @@ Dygraph.prototype.__init__ = function(div, file, attrs) { } if (!div) { - throw 'Constructing dygraph with a non-existent div!'; + throw new Error('Constructing dygraph with a non-existent div!'); } // Copy the important bits into the object -- 2.7.4