mirror of
https://github.com/ecomfe/vue-echarts.git
synced 2025-10-27 19:13:59 +08:00
test: increase coverage and add codecov integration
This commit is contained in:
53
tests/ssr.test.ts
Normal file
53
tests/ssr.test.ts
Normal file
@ -0,0 +1,53 @@
|
||||
import { describe, it, expect, vi } from "vitest";
|
||||
|
||||
// Mock non-browser environment for this file only
|
||||
vi.mock("/src/utils.ts", async (importOriginal: any) => {
|
||||
const actual: any = await importOriginal();
|
||||
return { ...actual, isBrowser: () => false };
|
||||
});
|
||||
|
||||
import { h, defineComponent, shallowRef, watchEffect } from "vue";
|
||||
import { render, cleanup } from "./helpers/testing";
|
||||
import { useSlotOption } from "../src/composables/slot";
|
||||
|
||||
describe("SSR environment", () => {
|
||||
it("slot: teleportedSlots undefined and formatter returns undefined", async () => {
|
||||
const exposed = shallowRef<any>();
|
||||
const Probe = defineComponent({
|
||||
setup(_, ctx) {
|
||||
const { teleportedSlots, patchOption } = useSlotOption(
|
||||
ctx.slots,
|
||||
() => {},
|
||||
);
|
||||
(ctx as any).expose({ teleportedSlots, patchOption });
|
||||
return () => h("div", teleportedSlots());
|
||||
},
|
||||
});
|
||||
|
||||
const Root = defineComponent({
|
||||
setup() {
|
||||
const r = shallowRef<any>();
|
||||
watchEffect(() => {
|
||||
if (r.value) exposed.value = r.value;
|
||||
});
|
||||
return () =>
|
||||
h(
|
||||
Probe,
|
||||
{ ref: (v: any) => (r.value = v) },
|
||||
{ tooltip: () => [h("span", "x")] },
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
render(Root);
|
||||
|
||||
const vnode = exposed.value!.teleportedSlots();
|
||||
expect(vnode).toBeUndefined();
|
||||
|
||||
const patched: any = exposed.value!.patchOption({});
|
||||
const container = patched.tooltip?.formatter?.({ dataIndex: 0 });
|
||||
expect(container).toBeUndefined();
|
||||
|
||||
cleanup();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user