diff --git a/src/core/echarts.ts b/src/core/echarts.ts index 8214c11e0e..3c60b2362d 100644 --- a/src/core/echarts.ts +++ b/src/core/echarts.ts @@ -1023,6 +1023,9 @@ class ECharts extends Eventful { return; } + // `opts` is optional, as the `opts && ...` reads below and `getDataURL` assume. + opts = opts || {}; + const isSvg = opts.type === 'svg'; const groupId = this.group; const mathMin = Math.min; diff --git a/test/ut/spec/api/getConnectedDataURL.test.ts b/test/ut/spec/api/getConnectedDataURL.test.ts new file mode 100644 index 0000000000..748a22a71e --- /dev/null +++ b/test/ut/spec/api/getConnectedDataURL.test.ts @@ -0,0 +1,60 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +import { createChart } from '../../core/utHelper'; +import { EChartsType } from '../../../../src/echarts'; + +describe('api_getConnectedDataURL', function () { + + let chart: EChartsType; + beforeEach(function () { + chart = createChart({width: 200, height: 150}); + chart.setOption({ + animation: false, + xAxis: {type: 'category', data: ['a', 'b']}, + yAxis: {type: 'value'}, + series: [{type: 'line', data: [1, 2]}] + }); + }); + afterEach(function () { + chart.dispose(); + }); + + // `opts` is optional — `getDataURL` normalizes it and the reads further down + // `getConnectedDataURL` are already written as `opts && opts.xxx`. Only the + // very first read was unguarded, so calling the API with no argument threw. + it('should accept being called with no argument', function () { + expect(function () { + chart.getConnectedDataURL(); + }).not.toThrow(); + }); + + it('should accept being called with an explicit undefined', function () { + expect(function () { + chart.getConnectedDataURL(undefined); + }).not.toThrow(); + }); + + it('should still accept an options object', function () { + expect(function () { + chart.getConnectedDataURL({type: 'png'}); + }).not.toThrow(); + }); + +});