zerodevx / svelte-toast

Simple elegant toast notifications
https://zerodevx.github.io/svelte-toast/
ISC License
835 stars 49 forks source link

Testing library + jest throw an error #62

Closed Iuriy-Budnikov closed 1 year ago

Iuriy-Budnikov commented 2 years ago

image

image

<script lang="ts">
  import { onMount } from 'svelte';
  import { SvelteToast } from '@zerodevx/svelte-toast';
  import type { SvelteToastOptions } from '@zerodevx/svelte-toast';
  import cx from 'clsx';
  import type { ClassValue } from 'clsx';
  import { canUseDOM } from '../../../components/utils/exenv';
  import './Toast.scss';
  /**
   * Classname
   */
  export let className: ClassValue = '';
  /**
   * SvelteToastOptions
   */
  export let options: SvelteToastOptions;
  /**
   * SvelteToastOptions target
   */
  export let target: string;
  // svelte toast doesn't support ssr
  let mounted = false;
  onMount(() => {
    if (canUseDOM) {
      mounted = true;
    }
  });
</script>

{#if mounted}
  <div class={cx('toast', className)}>
    <SvelteToast {options} {target} />
  </div>
{/if}
zerodevx commented 2 years ago

Likely related to #60