Skip to content

Commit 2e9add6

Browse files
committed
fix(test): 修改单测问题
1 parent 8ed451a commit 2e9add6

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

__tests__/unit/plots/gauge/index-spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe('gauge', () => {
9090
const annotations = gauge.chart.getComponents();
9191
expect(annotations.length).toBe(1);
9292
expect(annotations[0].extra.position).toEqual(['50%', '100%']);
93-
const annotation = document.body.querySelector('.g2-html-annotation');
93+
const annotation = gauge.chart.ele.querySelector('.g2-html-annotation');
9494
expect((annotation as HTMLElement).innerText).toBe('分数:75');
9595

9696
// @ts-ignore

__tests__/unit/plots/liquid/statistic-spec.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ describe('liquid statistic', () => {
1414

1515
it('默认展示', async () => {
1616
await delay(50);
17-
const annotations = document.body.querySelectorAll('.g2-html-annotation');
17+
const annotations = liquid.chart.ele.querySelectorAll('.g2-html-annotation');
1818
expect(annotations.length).toBe(1);
1919
});
2020

2121
it('默认展示当前数值', () => {
2222
liquid.update({ statistic: { content: {} } });
23-
const annotation = document.body.querySelector('.g2-html-annotation');
23+
const annotation = liquid.chart.ele.querySelector('.g2-html-annotation');
2424
expect((annotation as HTMLElement).innerText).toBe('65.00%');
2525
});
2626

@@ -29,24 +29,24 @@ describe('liquid statistic', () => {
2929
meta: { percent: { formatter: (v) => `${v * 100}.000%` } },
3030
statistic: { content: { formatter: null } },
3131
});
32-
const annotation = document.body.querySelector('.g2-html-annotation');
32+
const annotation = liquid.chart.ele.querySelector('.g2-html-annotation');
3333
expect((annotation as HTMLElement).innerText).toBe('65.000%');
3434
});
3535

3636
it('statistic 配置的格式化方式, 优先级高于 meta', () => {
3737
liquid.update({ statistic: { content: { formatter: ({ percent }) => `${percent * 100}.0%` } } });
38-
const annotation = document.body.querySelector('.g2-html-annotation');
38+
const annotation = liquid.chart.ele.querySelector('.g2-html-annotation');
3939
expect((annotation as HTMLElement).innerText).toBe('65.0%');
4040
});
4141

4242
it('statistic 配置title', () => {
4343
liquid.update({ statistic: { content: {}, title: {} } });
44-
let annotations = document.body.querySelectorAll('.g2-html-annotation');
44+
let annotations = liquid.chart.ele.querySelectorAll('.g2-html-annotation');
4545
expect(annotations.length).toBe(2);
4646
expect((annotations[0] as HTMLElement).innerText).toBe('');
4747

4848
liquid.update({ statistic: { content: {}, title: { formatter: () => '测试' } } });
49-
annotations = document.body.querySelectorAll('.g2-html-annotation');
49+
annotations = liquid.chart.ele.querySelectorAll('.g2-html-annotation');
5050
expect((annotations[0] as HTMLElement).innerText).toBe('测试');
5151
});
5252

@@ -72,29 +72,29 @@ describe('liquid statistic', () => {
7272

7373
it('关闭 statistic', () => {
7474
liquid.update({ statistic: { content: null } });
75-
let annotations = document.body.querySelectorAll('.g2-html-annotation');
75+
let annotations = liquid.chart.ele.querySelectorAll('.g2-html-annotation');
7676
expect(annotations.length).toBe(1);
7777
liquid.update({ statistic: { content: null, title: null } });
78-
annotations = document.body.querySelectorAll('.g2-html-annotation');
78+
annotations = liquid.chart.ele.querySelectorAll('.g2-html-annotation');
7979
expect(annotations.length).toBe(0);
8080
});
8181

8282
it('change data', () => {
8383
liquid.update({ statistic: { title: {}, content: { formatter: ({ percent: v }) => `${v * 100}.0%` } } });
8484
liquid.changeData(0.35);
85-
const annotations = document.body.querySelectorAll('.g2-html-annotation');
85+
const annotations = liquid.chart.ele.querySelectorAll('.g2-html-annotation');
8686
expect(annotations.length).toBe(2);
8787
expect((annotations[1] as HTMLElement).innerText).toBe('35.0%');
8888

8989
liquid.changeData(0.15);
90-
expect((document.body.querySelectorAll('.g2-html-annotation')[1] as HTMLElement).innerText).toBe('15.0%');
90+
expect((liquid.chart.ele.querySelectorAll('.g2-html-annotation')[1] as HTMLElement).innerText).toBe('15.0%');
9191

9292
liquid.update({ statistic: { content: {}, title: false } });
93-
expect(document.body.querySelectorAll('.g2-html-annotation').length).toBe(1);
94-
expect((document.body.querySelectorAll('.g2-html-annotation')[0] as HTMLElement).innerText).toBe('15.0%');
93+
expect(liquid.chart.ele.querySelectorAll('.g2-html-annotation').length).toBe(1);
94+
expect((liquid.chart.ele.querySelectorAll('.g2-html-annotation')[0] as HTMLElement).innerText).toBe('15.0%');
9595

9696
liquid.changeData(0.05);
97-
expect((document.body.querySelectorAll('.g2-html-annotation')[0] as HTMLElement).innerText).toBe('5.0%');
97+
expect((liquid.chart.ele.querySelectorAll('.g2-html-annotation')[0] as HTMLElement).innerText).toBe('5.0%');
9898
});
9999

100100
afterAll(() => {

__tests__/unit/plots/pie/interaction-spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe('register interaction', () => {
5454
action.reset();
5555

5656
delay(500);
57-
const htmlAnnotations = document.querySelectorAll('.g2-html-annotation');
57+
const htmlAnnotations = pie.chart.ele.querySelectorAll('.g2-html-annotation');
5858
expect((htmlAnnotations[0] as HTMLElement).innerText).toBe('Total' /** 中心文本指标卡,默认title */);
5959
});
6060

0 commit comments

Comments
 (0)