Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Unit tests for async url parameters in Svelte and Jest

$
0
0

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?


Viewing all articles
Browse latest Browse all 1541

Trending Articles