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 3b30d07
Showing 1 changed file with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,34 @@ describe(RouterHistoryStore.name, () => {
};
}

it('the URLs behave like the History API when navigating using links', async () => {
expect.assertions(2);

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 () => {
expect.assertions(2);

const { click, routerHistory } = await setup();
let currentUrl: string | undefined;
routerHistory.currentUrl$.subscribe((url) => {
Expand All @@ -119,4 +146,31 @@ 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 () => {
expect.assertions(2);

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 3b30d07

Please sign in to comment.