Skip to content

Commit af7fccb

Browse files
committed
added tests
1 parent 6e4e792 commit af7fccb

File tree

1 file changed

+61
-16
lines changed

1 file changed

+61
-16
lines changed

src/__tests__/index.test.js

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ describe('index', () => {
1717
echarts.instance.webview.postMessage = jest.fn();
1818
echarts.instance.clear();
1919

20-
expect(echarts.instance.webview.postMessage).toBeCalledWith('{"types":"CLEAR"}');
20+
expect(echarts.instance.webview.postMessage).toBeCalledWith(
21+
'{"types":"CLEAR"}',
22+
);
2123
});
2224

2325
it('getOption works', () => {
@@ -28,11 +30,13 @@ describe('index', () => {
2830
echarts.instance.postMessage = jest.fn();
2931
echarts.instance.getOption(() => {});
3032

31-
expect(echarts.instance.postMessage).toBeCalledWith(expect.objectContaining({
32-
properties: undefined,
33-
types: 'GET_OPTION',
34-
uuid: expect.any(String),
35-
}));
33+
expect(echarts.instance.postMessage).toBeCalledWith(
34+
expect.objectContaining({
35+
properties: undefined,
36+
types: 'GET_OPTION',
37+
uuid: expect.any(String),
38+
}),
39+
);
3640
});
3741

3842
it('setOption works', () => {
@@ -43,16 +47,55 @@ describe('index', () => {
4347
echarts.instance.postMessage = jest.fn();
4448
echarts.instance.setOption({ test: '12345' });
4549

46-
expect(echarts.instance.postMessage).toBeCalledWith(expect.objectContaining({
47-
payload: expect.objectContaining({
48-
lazyUpdate: false,
49-
notMerge: false,
50-
option: {
51-
test: '12345',
52-
},
50+
expect(echarts.instance.postMessage).toBeCalledWith(
51+
expect.objectContaining({
52+
payload: expect.objectContaining({
53+
lazyUpdate: false,
54+
notMerge: false,
55+
option: {
56+
test: '12345',
57+
},
58+
}),
59+
types: 'SET_OPTION',
5360
}),
54-
types: 'SET_OPTION',
55-
}));
61+
);
62+
});
63+
64+
it('setBackgroundColor works', () => {
65+
const jsx = <ECharts baseUrl="something" backgroundColor="red" />;
66+
const renderer = render(jsx);
67+
const echarts = renderer.getByType(ECharts);
68+
69+
echarts.instance.postMessage = jest.fn();
70+
echarts.instance.setBackgroundColor('orange');
71+
expect(echarts.instance.postMessage).toBeCalledWith({
72+
color: 'orange',
73+
types: 'SET_BACKGROUND_COLOR',
74+
});
75+
});
76+
77+
it('onMessage error', () => {
78+
global.console = { log: jest.fn() };
79+
80+
const jsx = <ECharts baseUrl="something" />;
81+
const renderer = render(jsx);
82+
83+
const echarts = renderer.getByType(ECharts);
84+
85+
echarts.instance.onMessage('test');
86+
87+
expect(console.log).toBeCalled();
88+
});
89+
90+
it('no baseUrl works', () => {
91+
jest.mock('Platform', () => {
92+
const Platform = require.requireActual('Platform');
93+
Platform.OS = 'android';
94+
return Platform;
95+
});
96+
97+
const jsx = <ECharts />;
98+
render(jsx);
5699
});
57100

58101
it('onMessage (CALLBACK) works', () => {
@@ -76,7 +119,9 @@ describe('index', () => {
76119
},
77120
});
78121

79-
expect(echarts.instance.callbacks['1234']).toBeCalledWith({ somevalue: 'helloworld' });
122+
expect(echarts.instance.callbacks['1234']).toBeCalledWith({
123+
somevalue: 'helloworld',
124+
});
80125
});
81126

82127
it('onMessage (DATA) works', () => {

0 commit comments

Comments
 (0)