Skip to content

Commit 7d3dd38

Browse files
committed
feat: update jest config
1 parent fb49444 commit 7d3dd38

File tree

13 files changed

+79
-55
lines changed

13 files changed

+79
-55
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hmarques98/react-native-template-typescript",
3-
"version": "1.0.6",
3+
"version": "1.0.8",
44
"description": "A minimal template with good architecture and common packages to let you focus on writing features right away.",
55
"scripts": {},
66
"files": [

template/.env.example

Lines changed: 0 additions & 3 deletions
This file was deleted.

template/.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ module.exports = {
3232
version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use
3333
},
3434
},
35+
env: {
36+
jest: true,
37+
},
3538
};

template/__tests__/App-test.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.

template/__tests__/App.test.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react';
2+
import { Button, Text, TextInput, View } from 'react-native';
3+
import { fireEvent, render, waitFor } from '@testing-library/react-native';
4+
5+
function Example() {
6+
const [name, setUser] = React.useState('');
7+
const [show, setShow] = React.useState(false);
8+
9+
return (
10+
<View>
11+
<TextInput value={name} onChangeText={setUser} testID="input" />
12+
<Button
13+
title="Print Username"
14+
onPress={() => {
15+
// let's pretend this is making a server request, so it's async
16+
// (you'd want to mock this imaginary request in your unit tests)...
17+
setTimeout(() => {
18+
setShow(!show);
19+
}, Math.floor(Math.random() * 200));
20+
}}
21+
/>
22+
{show && <Text testID="printed-username">{name}</Text>}
23+
</View>
24+
);
25+
}
26+
27+
test('examples of some things', async () => {
28+
const { getByTestId, getByText, queryByTestId, toJSON } = render(<Example />);
29+
const famousProgrammerInHistory = 'Ada Lovelace';
30+
31+
const input = getByTestId('input');
32+
fireEvent.changeText(input, famousProgrammerInHistory);
33+
34+
const button = getByText('Print Username');
35+
fireEvent.press(button);
36+
37+
await waitFor(() => expect(queryByTestId('printed-username')).toBeTruthy());
38+
39+
expect(getByTestId('printed-username').props.children).toBe(famousProgrammerInHistory);
40+
expect(toJSON()).toMatchSnapshot();
41+
});

template/_env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ENV=dev
2+
SENTRY_DSN=
3+
BASE_URL=https://fakerapi.it/api/v1/

template/jest.config.js

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,4 @@
1-
// eslint-disable-next-line @typescript-eslint/no-var-requires
2-
const jestPreset = require('@testing-library/react-native/jest-preset');
3-
41
module.exports = {
5-
testEnvironment: 'node',
62
preset: 'react-native',
7-
setupFiles: [
8-
'./jest.setup.js',
9-
'./node_modules/react-native-gesture-handler/jestSetup.js',
10-
'./node_modules/react-native/jest/setup.js',
11-
'./node_modules/react-native/Libraries/Utilities/__mocks__/BackHandler.js',
12-
],
13-
setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect'],
14-
clearMocks: true,
15-
moduleNameMapper: {
16-
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
17-
'<rootDir>/assetsTransformer.js',
18-
'\\.(css|less)$': '<rootDir>/assetsTransformer.js',
19-
'\\.svg': '<rootDir>/__mocks__/svgMocks.js',
20-
},
21-
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
3+
testEnvironment: 'node',
224
};

template/jest.setup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import '@testing-library/jest-native/extend-expect';
12
import mockRNCNetInfo from '@react-native-community/netinfo/jest/netinfo-mock.js';
23
import mockAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock';
3-
import React from 'react';
4-
import '@testing-library/jest-native/extend-expect';
4+
55
import { jest } from '@jest/globals';
66
import { server } from './src/test/mocks/server';
77

template/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "StarWarsApp",
2+
"name": "HelloWorld",
33
"version": "0.0.1",
44
"private": true,
55
"scripts": {
@@ -82,6 +82,7 @@
8282
"husky": "^5.1.3",
8383
"jest": "^26.6.3",
8484
"jest-circus": "^26.6.3",
85+
"jest-extended": "^0.11.5",
8586
"lint-staged": "^10.5.3",
8687
"metro-react-native-babel-preset": "^0.64.0",
8788
"patch-package": "^6.4.4",
@@ -101,5 +102,8 @@
101102
"prettier --write .",
102103
"jest --bail --findRelatedTests"
103104
]
105+
},
106+
"jest": {
107+
"transform": {}
104108
}
105109
}

template/src/components/CustomText.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { PropsWithChildren } from 'react';
22
import { Text, TextProps } from 'react-native';
3-
import styled, { css } from 'styled-components/native';
3+
import styled, { css, withTheme } from 'styled-components/native';
44
import { space, SpaceProps, layout, LayoutProps, compose, typography, TypographyProps } from 'styled-system';
55

66
interface StyleProps extends SpaceProps, TypographyProps, LayoutProps, TextProps {
@@ -21,9 +21,8 @@ const Container = styled(Text)<StyleProps>`
2121
border: 1px solid red;
2222
`
2323
: css``};
24-
text-align-vertical: center;
2524
text-decoration-line: ${({ underline }) => (underline ? 'underline' : 'none')};
26-
color: ${({ theme }) => theme.colors.primary};
25+
color: ${(props) => props.theme.colors.primary};
2726
${({ capitalize }) =>
2827
capitalize
2928
? css`
@@ -41,7 +40,7 @@ Container.defaultProps = {
4140
opacity: 1,
4241
};
4342

44-
const CustomText = ({ children, color, ...props }: PropsWithChildren<StyleProps>) => {
43+
const CustomText = ({ children, ...props }: PropsWithChildren<StyleProps>) => {
4544
return <Container {...props}>{children}</Container>;
4645
};
4746

0 commit comments

Comments
 (0)