\ No newline at end of file diff --git a/src/__tests__/fixtures/scoped-id.marko.d.ts b/src/__tests__/fixtures/scoped-id.marko.d.ts new file mode 100644 index 0000000..0a3c1f1 --- /dev/null +++ b/src/__tests__/fixtures/scoped-id.marko.d.ts @@ -0,0 +1,2 @@ +declare let x: any; +export = x; diff --git a/src/__tests__/render.browser.ts b/src/__tests__/render.browser.ts index 5d16e9e..828ac62 100644 --- a/src/__tests__/render.browser.ts +++ b/src/__tests__/render.browser.ts @@ -6,6 +6,7 @@ import UpdateCounter from "./fixtures/update-counter.marko"; import HelloWorld from "./fixtures/hello-world.marko"; import HelloName from "./fixtures/hello-name.marko"; import Clickable from "./fixtures/clickable.marko"; +import ScopedId from "./fixtures/scoped-id.marko"; afterEach(cleanup); @@ -143,3 +144,11 @@ test("fireEvent waits for pending updates", async () => { expect(getByText("Value: 1")).toBeInTheDocument(); }); + +test("it renders a stable scoped id", async () => { + const r1 = await render(ScopedId); + expect(r1.getByRole("main")).toHaveProperty("id", "c0-test"); + cleanup(); + const r2 = await render(ScopedId); + expect(r2.getByRole("main")).toHaveProperty("id", "c0-test"); +}); diff --git a/src/index-browser.ts b/src/index-browser.ts index 70fe9ac..86400a2 100644 --- a/src/index-browser.ts +++ b/src/index-browser.ts @@ -118,6 +118,7 @@ export async function render( export function cleanup() { mountedComponents.forEach(destroyComponent); + resetComponentIdCounter(); } function destroyComponent(component) { @@ -132,3 +133,10 @@ function destroyComponent(component) { mountedComponents.delete(container); } + +function resetComponentIdCounter() { + const counter = (window as any).$MUID; + if (counter) { + counter.i = 0; + } +} From da2b134f7cf24f872ebf2933cbcddd92f5addd33 Mon Sep 17 00:00:00 2001 From: Michael Rawlings Date: Fri, 21 Feb 2020 16:36:21 -0800 Subject: [PATCH 2/2] fix: add istanbul ignore comment --- src/index-browser.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index-browser.ts b/src/index-browser.ts index 86400a2..1752193 100644 --- a/src/index-browser.ts +++ b/src/index-browser.ts @@ -136,6 +136,7 @@ function destroyComponent(component) { function resetComponentIdCounter() { const counter = (window as any).$MUID; + /* istanbul ignore else */ if (counter) { counter.i = 0; }