From: Dan Vanderkam Date: Sat, 28 Mar 2015 18:31:57 +0000 (-0400) Subject: Test non-existent divs X-Git-Tag: v2.0.0~66^2~5 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=5db9ad5da775ff73aa8d859c334935d01f01b930;p=dygraphs.git Test non-existent divs --- 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