testing-library/svelte-testing-library

How I can test dynamic import with svelte

AdaltonLeite opened this issue · 2 comments

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?

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

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