Here is an official solution on the testing library website:
https://testing-library.com/docs/svelte-testing-library/faq/#why-isnt-onmount-called-when-rendering-components