test: clean up code and improve test coverage

This commit is contained in:
Justineo
2025-11-25 13:48:29 +08:00
parent cfef3c97e0
commit 8d68e2b9c1
7 changed files with 146 additions and 29 deletions

View File

@@ -413,7 +413,13 @@ describe("ECharts component", () => {
await nextTick();
chartStub.dispose.mockClear();
exposed.value.root.value = undefined;
Object.defineProperty(exposed.value.root, "value", {
configurable: true,
get: () => undefined,
set: () => {
/* ignore */
},
});
screen.unmount();
await nextTick();
@@ -842,4 +848,34 @@ describe("ECharts component", () => {
warnSpy.mockRestore();
});
it("ignores falsy listeners during event binding", async () => {
const option = ref({});
const exposed = shallowRef<any>();
renderChart(
() => ({ option: option.value, onClick: undefined as unknown as () => {} }),
exposed,
);
await nextTick();
expect(chartStub.on).not.toHaveBeenCalled();
});
it("skips option watcher when chart instance is missing", async () => {
const option = ref<any>(null);
const exposed = shallowRef<any>();
init.mockImplementation(() => undefined as any);
renderChart(() => ({ option: option.value }), exposed);
await nextTick();
chartStub.setOption.mockClear();
option.value = { title: { text: "later" } };
await nextTick();
expect(chartStub.setOption).not.toHaveBeenCalled();
});
});