diff --git a/__tests__/unit/plots/pie/index-spec.ts b/__tests__/unit/plots/pie/index-spec.ts index fa7e35d396..fd043ea954 100644 --- a/__tests__/unit/plots/pie/index-spec.ts +++ b/__tests__/unit/plots/pie/index-spec.ts @@ -20,6 +20,9 @@ describe('pie', () => { }); pie.render(); + expect(pie.type).toBe('pie'); + // @ts-ignore + expect(pie.getDefaultOptions()).toBe(Pie.getDefaultOptions()); const geometry = pie.chart.geometries[0]; const elements = geometry.elements; diff --git a/__tests__/unit/plots/pie/statistic-spec.ts b/__tests__/unit/plots/pie/statistic-spec.ts index 02beb90226..fae1787f97 100644 --- a/__tests__/unit/plots/pie/statistic-spec.ts +++ b/__tests__/unit/plots/pie/statistic-spec.ts @@ -1,5 +1,6 @@ import { Chart } from '@antv/g2'; import { Pie, PieOptions } from '../../../../src'; +import { DEFAULT_OPTIONS } from '../../../../src/plots/pie/contants'; import { POSITIVE_NEGATIVE_DATA } from '../../../data/common'; import { delay } from '../../../utils/delay'; import { createDiv } from '../../../utils/dom'; @@ -301,6 +302,22 @@ describe('中心文本 - 指标卡', () => { expect(htmlAnnotations[0].getBoundingClientRect().width).toEqual(600); }); + it('statistic 默认继承 defaultOptions', () => { + pie.update({ statistic: null }); + expect(pie.chart.ele.querySelectorAll('.g2-html-annotation').length).toBe(0); + + pie.update({ statistic: {} }); + expect(pie.chart.ele.querySelectorAll('.g2-html-annotation').length).toBe(2); + expect(pie.options.statistic).toEqual({}); + setTimeout(() => { + // @ts-ignore + const annotations = pie.chart.ele.querySelectorAll('.g2-html-annotation') as HTMLDivElement[]; + expect(annotations[0].style.fontSize).toEqual(DEFAULT_OPTIONS.statistic.title.fontSize); + expect(annotations[1].style.color).toEqual(DEFAULT_OPTIONS.statistic.content.color); + expect(annotations[1].style).toMatchObject(DEFAULT_OPTIONS.statistic.content); + }, 0); + }); + afterEach(() => { pie.chart.clear(); });