Skip to content

Commit 4141703

Browse files
committed
Add tests for finding last location
1 parent f64458d commit 4141703

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

packages/vue-router/__tests__/locationHistory.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,25 @@ describe('Location History', () => {
8484
expect(locationHistory.canGoBack(1, 0, 1)).toEqual(true);
8585
expect(locationHistory.canGoBack(2, 0, 1)).toEqual(false);
8686
});
87+
88+
it('should correctly find the last location', () => {
89+
const [home, pageA, pageB, pageC] = [
90+
{ pathname: '/home' },
91+
{ pathname: '/page-a', pushedByRoute: '/home' },
92+
{ pathname: '/page-b', pushedByRoute: '/page-a' },
93+
{ pathname: '/page-c', pushedByRoute: '/page-b' },
94+
];
95+
96+
locationHistory.add(home);
97+
locationHistory.add(pageA);
98+
locationHistory.add(pageB);
99+
locationHistory.add(pageC);
100+
101+
expect(locationHistory.findLastLocation(pageB)).toEqual(pageA);
102+
expect(locationHistory.findLastLocation(pageB, -2)).toEqual(home);
103+
104+
expect(locationHistory.findLastLocation(pageC)).toEqual(pageB);
105+
expect(locationHistory.findLastLocation(pageC, -2)).toEqual(pageA);
106+
expect(locationHistory.findLastLocation(pageC, -3)).toEqual(home);
107+
});
87108
});

0 commit comments

Comments
 (0)