-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: render with events utility refactoring (#554)
# Motivation Using an `$on` callback for testing is deprecated in Svelte v5 (PR #548). Instead, we will now use the `events` option of `render`, which itself will eventually be replaced by the library. To minimize changes in the Svelte v5 PR, we refactored the test to use a utility function that handles rendering and event binding. # Changes - Introduce and use `renderWithEvents` utilitiy. --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
78b8864
commit e4ada9a
Showing
7 changed files
with
119 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { | ||
render as svelteRender, | ||
type RenderResult, | ||
} from "@testing-library/svelte"; | ||
import type { ComponentProps, ComponentType, SvelteComponent } from "svelte"; | ||
|
||
export const render = <C extends SvelteComponent>( | ||
cmp: ComponentType<C>, | ||
options?: { | ||
props?: ComponentProps<C>; | ||
events?: Record<string, ($event: CustomEvent) => void>; | ||
}, | ||
): RenderResult<C> => { | ||
const { component, ...rest } = svelteRender(cmp, { props: options?.props }); | ||
|
||
const events = Object.entries(options?.events ?? {}); | ||
|
||
events.forEach(([event, fn]) => { | ||
component.$on(event, fn); | ||
}); | ||
|
||
return { component, ...rest }; | ||
}; |