In Svelte onMount I'm doing following logic.
onMount(async () => { projectId = await new URLSearchParams(window.location.search).get('p'); jobId = await new URLSearchParams(window.location.search).get('j'); getJobs(); });
Then I have following test
test('will call getJobs endpoint on page load', () => { render(SingleJobView); setTimeout(() => { expect(getJobs).toHaveBeenCalled(); }, 1000); });
The problem is, that unit test will not pass without setTimeout
.How can I test the projectId, jobId
as mocked url parameters and getJobs
endpoint call without setTimeout
?