testing-library / svelte-testing-library

:chipmunk: Simple and complete Svelte DOM testing utilities that encourage good testing practices
https://testing-library.com/docs/svelte-testing-library/intro
MIT License
615 stars 33 forks source link

How I can test dynamic import with svelte #253

Closed AdaltonLeite closed 8 months ago

AdaltonLeite commented 1 year ago

Hi guys,

Has anyone tried testing dynamic imports with svelte?

I have the following scenario:

<script lang="ts">
let Component: ComponentType<SvelteComponentTyped<Component>>;
onMount(async () => {
    Component = (await import('../../../component')).Default;
  });
</script>

<svelte:component this={Component} ... />

In my test when I try to render this dynamic component it always fails and in the output I realize that it does not even render the component in fact, it seems that it does not wait for the promise to be resolved, has anyone gone through this or has any suggestions?

yanick commented 1 year ago

I think this is #222 rearing its ugly head. The short of it is: onMount() is not called in a SSR context.

yanick commented 8 months ago

There was no reply from the original poster, so I'll indeed chalk it up to #222 and close this issue.