Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ad4145
commit 976d8bf
Showing
5 changed files
with
164 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import React, { Text } from 'react-native'; | ||
|
||
import { router } from '../exports'; | ||
import { act, renderRouter, screen, testRouter } from '../testing-library'; | ||
|
||
it('can push a hash url', () => { | ||
renderRouter({ | ||
index: () => <Text testID="index" />, | ||
test: () => <Text testID="test" />, | ||
}); | ||
|
||
expect(screen).toHavePathname('/'); | ||
expect(screen.getByTestId('index')).toBeOnTheScreen(); | ||
|
||
act(() => router.push('/test#my-hash')); | ||
expect(screen.getByTestId('test')).toBeOnTheScreen(); | ||
|
||
expect(screen).toHaveSegments(['test']); | ||
expect(screen).toHavePathname('/test'); | ||
expect(screen).toHavePathnameWithParams('/test#my-hash'); | ||
expect(screen).toHaveSearchParams({ '#': 'my-hash' }); | ||
}); | ||
|
||
it('route.push() with hash', () => { | ||
renderRouter({ | ||
index: () => <Text testID="index" />, | ||
test: () => <Text testID="test" />, | ||
}); | ||
|
||
expect(screen).toHavePathname('/'); | ||
expect(screen.getByTestId('index')).toBeOnTheScreen(); | ||
|
||
act(() => router.push('/test#a')); | ||
expect(screen.getByTestId('test')).toBeOnTheScreen(); | ||
|
||
expect(screen).toHaveSegments(['test']); | ||
expect(screen).toHavePathname('/test'); | ||
expect(screen).toHavePathnameWithParams('/test#a'); | ||
expect(screen).toHaveSearchParams({ '#': 'a' }); | ||
|
||
act(() => router.push('/test#b')); | ||
act(() => router.push('/test#b')); | ||
|
||
expect(screen).toHavePathnameWithParams('/test#b'); | ||
expect(screen).toHaveSearchParams({ '#': 'b' }); | ||
|
||
act(() => router.push('/test#c')); | ||
expect(screen).toHavePathnameWithParams('/test#c'); | ||
expect(screen).toHaveSearchParams({ '#': 'c' }); | ||
|
||
act(() => router.back()); | ||
expect(screen).toHavePathname('/test'); | ||
expect(screen).toHavePathnameWithParams('/test#b'); | ||
expect(screen).toHaveSearchParams({ '#': 'b' }); | ||
|
||
act(() => router.back()); | ||
expect(screen).toHavePathname('/test'); | ||
expect(screen).toHavePathnameWithParams('/test#a'); | ||
expect(screen).toHaveSearchParams({ '#': 'a' }); | ||
|
||
act(() => router.back()); | ||
expect(screen).toHavePathname('/'); | ||
}); | ||
|
||
it('works with search params', () => { | ||
renderRouter({ | ||
index: () => <Text testID="index" />, | ||
test: () => <Text testID="test" />, | ||
}); | ||
|
||
expect(screen).toHavePathname('/'); | ||
expect(screen.getByTestId('index')).toBeOnTheScreen(); | ||
|
||
act(() => router.navigate('/test?a=1#my-hash')); | ||
|
||
expect(screen.getByTestId('test')).toBeOnTheScreen(); | ||
expect(screen).toHaveSegments(['test']); | ||
expect(screen).toHavePathname('/test'); | ||
expect(screen).toHavePathnameWithParams('/test?a=1#my-hash'); | ||
expect(screen).toHaveSearchParams({ a: '1', '#': 'my-hash' }); | ||
|
||
act(() => router.navigate('/test?a=2#my-hash')); | ||
expect(screen).toHaveSegments(['test']); | ||
expect(screen).toHavePathname('/test'); | ||
expect(screen).toHavePathnameWithParams('/test?a=2#my-hash'); | ||
expect(screen).toHaveSearchParams({ a: '2', '#': 'my-hash' }); | ||
|
||
act(() => router.navigate('/test?a=2#my-new-hash')); | ||
expect(screen).toHaveSegments(['test']); | ||
expect(screen).toHavePathname('/test'); | ||
expect(screen).toHavePathnameWithParams('/test?a=2#my-new-hash'); | ||
expect(screen).toHaveSearchParams({ a: '2', '#': 'my-new-hash' }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters