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
67 changes: 67 additions & 0 deletions src/lib/directives/transition.directives.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import {
fade as svelteFade,
fly as svelteFly,
scale as svelteScale,
type FadeParams,
type TransitionConfig,
} from "svelte/transition";

/**
* A wrapper around Svelte's `fade` 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 {FadeParams} [params] - Optional parameters for the fade transition.
* @returns {TransitionConfig} The transition configuration, or an empty object in test mode.
*/
export const testSafeFade = (
node: HTMLElement,
params?: FadeParams | undefined,
): TransitionConfig => {
if (process.env.NODE_ENV === "test") {
return {};
}

return svelteFade(node, params);
};

/**
* A wrapper around Svelte's `fly` 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 {FlyParams} [params] - Optional parameters for the fly transition.
* @returns {TransitionConfig} The transition configuration, or an empty object in test mode.
*/
export const testSafeFly = (
node: HTMLElement,
params?: FadeParams | undefined,
): TransitionConfig => {
if (process.env.NODE_ENV === "test") {
return {};
}

return svelteFly(node, params);
};

/**
* A wrapper around Svelte's `scale` 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 {ScaleParams} [params] - Optional parameters for the scale transition.
* @returns {TransitionConfig} The transition configuration, or an empty object in test mode.
*/
export const testSafeScale = (
node: HTMLElement,
params?: FadeParams | undefined,
): TransitionConfig => {
if (process.env.NODE_ENV === "test") {
return {};
}

return svelteScale(node, params);
};
1 change: 1 addition & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from "./components";
export * from "./constants/constants";
export * from "./directives/transition.directives";
export * from "./icons";
export * from "./stores/busy.store";
export * from "./stores/layout.store";
Expand Down
Loading