Skip to content

Commit

Permalink
test: cover RouterHistoryStore with more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
LayZeeDK committed Dec 26, 2022
1 parent edf86d3 commit 9f3877c
Showing 1 changed file with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,29 @@ describe(RouterHistoryStore.name, () => {
};
}

it('the URLs behave like the History API when navigating using links', async () => {
const { click, routerHistory } = await setup();
let currentUrl: string | undefined;
routerHistory.currentUrl$.subscribe((url) => {
currentUrl = url;
});
let previousUrl: string | null | undefined;
routerHistory.previousUrl$.subscribe((url) => {
previousUrl = url;
});

// At Home
await click('#about-link');
// At About
await click('#company-link');
// At Company
await click('#products-link');
// At Products

expect(currentUrl).toBe('/products');
expect(previousUrl).toBe('/company');
});

it('the URLs behave like the History API when navigating back', async () => {
const { click, routerHistory } = await setup();
let currentUrl: string | undefined;
Expand All @@ -119,4 +142,29 @@ describe(RouterHistoryStore.name, () => {
expect(currentUrl).toBe('/about');
expect(previousUrl).toBe('/home');
});

it('the URLs behave like the History API when navigating back then using links', async () => {
const { click, routerHistory } = await setup();
let currentUrl: string | undefined;
routerHistory.currentUrl$.subscribe((url) => {
currentUrl = url;
});
let previousUrl: string | null | undefined;
routerHistory.previousUrl$.subscribe((url) => {
previousUrl = url;
});

// At Home
await click('#about-link');
// At About
await click('#company-link');
// At Company
await click('#back-link');
// At About
await click('#products-link');
// At Products

expect(currentUrl).toBe('/products');
expect(previousUrl).toBe('/about');
});
});

0 comments on commit 9f3877c

Please sign in to comment.