Skip to content

Commit 3b30d07

Browse files
committed
test: cover RouterHistoryStore with more test cases
1 parent edf86d3 commit 3b30d07

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

packages/router-component-store/src/lib/router-history-store/router-history.store.spec.ts

+54
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,34 @@ describe(RouterHistoryStore.name, () => {
9797
};
9898
}
9999

100+
it('the URLs behave like the History API when navigating using links', async () => {
101+
expect.assertions(2);
102+
103+
const { click, routerHistory } = await setup();
104+
let currentUrl: string | undefined;
105+
routerHistory.currentUrl$.subscribe((url) => {
106+
currentUrl = url;
107+
});
108+
let previousUrl: string | null | undefined;
109+
routerHistory.previousUrl$.subscribe((url) => {
110+
previousUrl = url;
111+
});
112+
113+
// At Home
114+
await click('#about-link');
115+
// At About
116+
await click('#company-link');
117+
// At Company
118+
await click('#products-link');
119+
// At Products
120+
121+
expect(currentUrl).toBe('/products');
122+
expect(previousUrl).toBe('/company');
123+
});
124+
100125
it('the URLs behave like the History API when navigating back', async () => {
126+
expect.assertions(2);
127+
101128
const { click, routerHistory } = await setup();
102129
let currentUrl: string | undefined;
103130
routerHistory.currentUrl$.subscribe((url) => {
@@ -119,4 +146,31 @@ describe(RouterHistoryStore.name, () => {
119146
expect(currentUrl).toBe('/about');
120147
expect(previousUrl).toBe('/home');
121148
});
149+
150+
it('the URLs behave like the History API when navigating back then using links', async () => {
151+
expect.assertions(2);
152+
153+
const { click, routerHistory } = await setup();
154+
let currentUrl: string | undefined;
155+
routerHistory.currentUrl$.subscribe((url) => {
156+
currentUrl = url;
157+
});
158+
let previousUrl: string | null | undefined;
159+
routerHistory.previousUrl$.subscribe((url) => {
160+
previousUrl = url;
161+
});
162+
163+
// At Home
164+
await click('#about-link');
165+
// At About
166+
await click('#company-link');
167+
// At Company
168+
await click('#back-link');
169+
// At About
170+
await click('#products-link');
171+
// At Products
172+
173+
expect(currentUrl).toBe('/products');
174+
expect(previousUrl).toBe('/about');
175+
});
122176
});

0 commit comments

Comments
 (0)