Skip to content

Commit

Permalink
fix: improve commonjs support for ssr screen api
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Jun 11, 2021
1 parent 8672ae2 commit 4ef10a3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export { FireFunction, FireObject, fireEvent } from "./shared";

export type RenderResult = AsyncReturnValue<typeof render>;

export let screen: typeof testingLibraryScreen;
export const screen: typeof testingLibraryScreen = {} as any;

let activeContainer: DocumentFragment | undefined;

Expand Down Expand Up @@ -50,8 +50,7 @@ export async function render<T extends Template>(
));
(container as any).outerHTML = html; // Fixes prettyDOM for container

// For SSR tests screen is always the last rendered component.
screen = {
const queries = {
debug: function debug(element, maxLength, options) {
if (!element) {
debug(Array.from(container.children), maxLength, options);
Expand All @@ -66,6 +65,9 @@ export async function render<T extends Template>(
...within(container as any as HTMLElement),
} as typeof testingLibraryScreen;

// For SSR tests screen is always references the last rendered component.
Object.assign(screen, queries);

return {
container,
emitted<N extends string = "*">(
Expand All @@ -89,7 +91,7 @@ export async function render<T extends Template>(

cleanupComponent();
},
...screen,
...queries,
} as const;
}

Expand Down

0 comments on commit 4ef10a3

Please sign in to comment.