diff --git a/src/lib/directives/transition.directives.ts b/src/lib/directives/transition.directives.ts index 9a2d8e82..51718ce6 100644 --- a/src/lib/directives/transition.directives.ts +++ b/src/lib/directives/transition.directives.ts @@ -2,9 +2,11 @@ import { fade as svelteFade, fly as svelteFly, scale as svelteScale, + slide as svelteSlide, type FadeParams, type FlyParams, type ScaleParams, + type SlideParams, type TransitionConfig, } from "svelte/transition"; @@ -67,3 +69,23 @@ export const testSafeScale = ( return svelteScale(node, params); }; + +/** + * A wrapper around Svelte's `slide` transition that disables itself in test mode. + * + * Prevents the test error "Cannot set properties of undefined (setting 'onfinish')". + * + * @param {HTMLElement} node - The HTML element to apply the transition to. + * @param {SlideParams} [params] - Optional parameters for the slide transition. + * @returns {TransitionConfig} The transition configuration, or an empty object in test mode. + */ +export const testSafeSlide = ( + node: HTMLElement, + params?: SlideParams | undefined, +): TransitionConfig => { + if (process.env.NODE_ENV === "test") { + return {}; + } + + return svelteSlide(node, params); +};