mirror of
https://github.com/ecomfe/vue-echarts.git
synced 2025-12-13 04:51:58 +08:00
test: add case for direct cleanup on registration failure
This commit is contained in:
@@ -351,7 +351,6 @@ export default defineComponent({
|
||||
// transition.
|
||||
root.value.__dispose = cleanup;
|
||||
} else {
|
||||
/* c8 ignore next */
|
||||
cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
48
tests/echarts-unregistered.test.ts
Normal file
48
tests/echarts-unregistered.test.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { describe, it, expect, beforeEach, vi } from "vitest";
|
||||
import { defineComponent, h, nextTick, shallowRef } from "vue";
|
||||
|
||||
import { render } from "./helpers/testing";
|
||||
import { enqueueChart, resetECharts, type ChartStub } from "./helpers/mock";
|
||||
|
||||
let chartStub: ChartStub;
|
||||
|
||||
describe("ECharts component (wc unregistered)", () => {
|
||||
beforeEach(() => {
|
||||
resetECharts();
|
||||
chartStub = enqueueChart();
|
||||
});
|
||||
|
||||
it("calls cleanup directly when web component registration fails", async () => {
|
||||
vi.resetModules();
|
||||
|
||||
vi.doMock("../src/wc", () => ({
|
||||
TAG_NAME: "x-vue-echarts",
|
||||
register: () => false,
|
||||
}));
|
||||
|
||||
const { default: ECharts } = await import("../src/ECharts");
|
||||
|
||||
const exposed = shallowRef<any>();
|
||||
const Root = defineComponent({
|
||||
setup() {
|
||||
return () =>
|
||||
h(ECharts, {
|
||||
option: { title: { text: "no-wc" } },
|
||||
ref: (v: any) => (exposed.value = v),
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
const screen = render(Root);
|
||||
await nextTick();
|
||||
|
||||
chartStub.dispose.mockClear();
|
||||
|
||||
screen.unmount();
|
||||
await nextTick();
|
||||
|
||||
expect(chartStub.dispose).toHaveBeenCalledTimes(1);
|
||||
|
||||
vi.doUnmock("../src/wc");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user