Skip to content

Commit f81ba08

Browse files
committed
fix: add react-navigation
1 parent 6082227 commit f81ba08

File tree

20 files changed

+499
-26
lines changed

20 files changed

+499
-26
lines changed

src/__tests__/index.tsx

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`should render correctly 1`] = `
4+
<View
5+
style={
6+
Object {
7+
"alignItems": "center",
8+
"flex": 1,
9+
"justifyContent": "center",
10+
}
11+
}
12+
testID="wrapper"
13+
>
14+
<Text>
15+
hello
16+
</Text>
17+
</View>
18+
`;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
import {Container} from '..';
3+
import renderer from 'react-test-renderer';
4+
import {Text} from 'react-native';
5+
6+
it('should render correctly', () => {
7+
const component = renderer.create(
8+
<Container testID="wrapper">
9+
<Text>hello</Text>
10+
</Container>,
11+
);
12+
13+
expect(component.toJSON()).toMatchSnapshot();
14+
});

src/components/Container/index.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React, {ReactNode} from 'react';
2+
import {View} from 'react-native';
3+
import {styles} from './styles';
4+
5+
type Props = {
6+
children: ReactNode | ReactNode[];
7+
testID?: string;
8+
};
9+
10+
export function Container({children, testID}: Props) {
11+
return (
12+
<View style={styles.center} testID={testID}>
13+
{children}
14+
</View>
15+
);
16+
}

src/components/Container/styles.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {StyleSheet} from 'react-native';
2+
3+
export const styles = StyleSheet.create({
4+
center: {
5+
flex: 1,
6+
alignItems: 'center',
7+
justifyContent: 'center',
8+
},
9+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {StyleSheet} from 'react-native';
2+
3+
export const styles = StyleSheet.create({
4+
center: {
5+
alignItems: 'center',
6+
justifyContent: 'center',
7+
height: '100vh',
8+
},
9+
});

src/components/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Container';

src/index.tsx

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
1-
import React, { memo } from "react";
2-
import { AppRegistry, View, Text, Platform, StyleSheet } from "react-native";
1+
import React from 'react';
2+
import {AppRegistry, Platform} from 'react-native';
3+
import {Navigation} from './navigation';
34

4-
const appName = "example";
5-
const styles = StyleSheet.create({
6-
container: { flex: 1, justifyContent: "center", alignItems: "center" }
7-
});
8-
9-
export const Main = memo(function Main() {
10-
return (
11-
<View style={styles.container}>
12-
<Text>react native with web and typescript</Text>
13-
</View>
14-
);
15-
});
5+
export function App() {
6+
return <Navigation />;
7+
}
168

17-
AppRegistry.registerComponent(appName, () => Main);
18-
if (Platform.OS === "web") {
19-
AppRegistry.runApplication(appName, {
20-
rootTag: document.getElementById("root")
9+
AppRegistry.registerComponent('example', () => App);
10+
if (Platform.OS === 'web') {
11+
AppRegistry.runApplication('example', {
12+
rootTag: document.getElementById('root'),
2113
});
2214
}

src/mocks/Files/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
process: (_, filename) =>
5+
`module.exports = '${JSON.stringify(path.basename(filename))}';`,
6+
};

src/mocks/Setup/index.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import 'react-native-gesture-handler/jestSetup';
2+
3+
jest.useFakeTimers();
4+
5+
jest.mock('react-native-reanimated', () => {
6+
const Reanimated = require('react-native-reanimated/mock');
7+
Reanimated.default.call = () => {};
8+
return Reanimated;
9+
});
10+
11+
jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper');
12+
13+
export const mockNavigation = {
14+
goBack: jest.fn(),
15+
navigate: jest.fn(),
16+
push: jest.fn(),
17+
popToTop: jest.fn(),
18+
};
19+
jest.mock('@react-navigation/native', () => {
20+
return {
21+
useRoute: () => jest.fn(),
22+
useNavigation: () => ({
23+
goBack: mockNavigation.goBack,
24+
navigate: mockNavigation.navigate,
25+
push: mockNavigation.push,
26+
popToTop: mockNavigation.popToTop,
27+
}),
28+
};
29+
});

0 commit comments

Comments
 (0)