Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/__tests__/fixtures/scoped-id.marko
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div role="main" id:scoped="test"/>
2 changes: 2 additions & 0 deletions src/__tests__/fixtures/scoped-id.marko.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare let x: any;
export = x;
9 changes: 9 additions & 0 deletions src/__tests__/render.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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");
});
9 changes: 9 additions & 0 deletions src/index-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export async function render<T extends Template>(

export function cleanup() {
mountedComponents.forEach(destroyComponent);
resetComponentIdCounter();
}

function destroyComponent(component) {
Expand All @@ -132,3 +133,11 @@ function destroyComponent(component) {

mountedComponents.delete(container);
}

function resetComponentIdCounter() {
const counter = (window as any).$MUID;
/* istanbul ignore else */
if (counter) {
counter.i = 0;
}
}