Skip to content
This repository was archived by the owner on Jul 30, 2020. It is now read-only.

Commit d377026

Browse files
authored
feat: change the mocked core components (#10)
1 parent 49f2b0d commit d377026

File tree

100 files changed

+913
-1311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+913
-1311
lines changed

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
node_modules
2-
coverage
3-
dist
4-
.idea
1+
node_modules/
2+
coverage/
3+
dist/
4+
.idea/
55
.DS_Store
66

77
yarn-error.log

examples/__tests__/input-event.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
2-
import { Text, TextInput, View } from 'react-native';
3-
import { render, fireEvent } from 'native-testing-library';
2+
import { TextInput } from 'react-native';
3+
import { render, fireEvent } from '../../src';
44

55
class CostInput extends React.Component {
66
state = {

examples/__tests__/react-context.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'jest-native/extend-expect';
22
import React from 'react';
33
import { Text } from 'react-native';
4-
import { render } from 'native-testing-library';
4+
import { render } from '../../src';
55

66
import { NameContext, NameProvider, NameConsumer } from '../react-context';
77

examples/__tests__/react-intl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { FormattedDate } from 'react-intl-native';
55
import IntlPolyfill from 'intl';
66
import 'intl/locale-data/jsonp/pt';
77

8-
import { getByText, render } from 'native-testing-library';
8+
import { getByText, render } from '../../src';
99

1010
const setupTests = () => {
1111
if (global.Intl) {

examples/__tests__/react-navigation.js

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33
import { Button, Text, View } from 'react-native';
44
import { createStackNavigator, createAppContainer, withNavigation } from 'react-navigation';
55

6-
import { render, fireEvent } from 'native-testing-library';
6+
import { render, fireEvent } from '../../src';
77

88
jest.mock('NativeAnimatedHelper').mock('react-native-gesture-handler', () => {
99
const View = require('react-native').View;
@@ -15,25 +15,6 @@ jest.mock('NativeAnimatedHelper').mock('react-native-gesture-handler', () => {
1515
};
1616
});
1717

18-
const originalConsoleWarn = console.warn;
19-
console.warn = arg => {
20-
const warnings = [
21-
'Calling .measureInWindow()',
22-
'Calling .measureLayout()',
23-
'Calling .setNativeProps()',
24-
'Calling .focus()',
25-
'Calling .blur()',
26-
];
27-
28-
const finalArgs = warnings.reduce((acc, curr) => (arg.includes(curr) ? [...acc, arg] : acc), []);
29-
30-
if (finalArgs.length) {
31-
return;
32-
}
33-
34-
originalConsoleWarn(message);
35-
};
36-
3718
const Home = ({ navigation }) => (
3819
<View>
3920
<Text testID="title">Home page</Text>
@@ -70,14 +51,14 @@ function renderWithNavigation({ screens = {}, navigatorConfig = {} } = {}) {
7051

7152
const App = createAppContainer(AppNavigator);
7253

73-
return { ...render(<App />), navigationContainer: App };
54+
return { ...render(<App detached />), navigationContainer: App };
7455
}
7556

7657
test('full app rendering/navigating', async () => {
77-
const { findByText, getByTestId, getByText } = renderWithNavigation();
58+
const { findByText, getByTestId, getByTitle } = renderWithNavigation();
7859

7960
expect(getByTestId('title')).toHaveTextContent('Home page');
80-
fireEvent.press(getByText(/Go to about/i));
61+
fireEvent.press(getByTitle(/Go to about/i));
8162

8263
const result = await findByText('About page');
8364
expect(result).toHaveTextContent('About page');

examples/__tests__/react-redux.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33
import { createStore } from 'redux';
44
import { Provider, connect } from 'react-redux';
55
import { Button, Text, View } from 'react-native';
6-
import { render, fireEvent } from 'native-testing-library';
6+
import { render, fireEvent } from '../../src';
77

88
class Counter extends React.Component {
99
increment = () => {
@@ -53,26 +53,26 @@ function renderWithRedux(ui, { initialState, store = createStore(reducer, initia
5353
}
5454

5555
test('can render with redux with defaults', () => {
56-
const { getByTestId, getByText } = renderWithRedux(<ConnectedCounter />);
57-
fireEvent.press(getByText('+'));
56+
const { getByTestId, getByTitle } = renderWithRedux(<ConnectedCounter />);
57+
fireEvent.press(getByTitle('+'));
5858
expect(getByTestId('count-value')).toHaveTextContent(1);
5959
});
6060

6161
test('can render with redux with custom initial state', () => {
62-
const { getByTestId, getByText } = renderWithRedux(<ConnectedCounter />, {
62+
const { getByTestId, getByTitle } = renderWithRedux(<ConnectedCounter />, {
6363
initialState: { count: 3 },
6464
});
65-
fireEvent.press(getByText('-'));
65+
fireEvent.press(getByTitle('-'));
6666
expect(getByTestId('count-value')).toHaveTextContent(2);
6767
});
6868

6969
test('can render with redux with custom store', () => {
7070
const store = createStore(() => ({ count: 1000 }));
71-
const { getByTestId, getByText } = renderWithRedux(<ConnectedCounter />, {
71+
const { getByTestId, getByTitle } = renderWithRedux(<ConnectedCounter />, {
7272
store,
7373
});
74-
fireEvent.press(getByText('+'));
74+
fireEvent.press(getByTitle('+'));
7575
expect(getByTestId('count-value')).toHaveTextContent(1000);
76-
fireEvent.press(getByText('-'));
76+
fireEvent.press(getByTitle('-'));
7777
expect(getByTestId('count-value')).toHaveTextContent(1000);
7878
});

examples/__tests__/update-props.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import 'jest-native/extend-expect';
33
import { Text, View } from 'react-native';
4-
import { render } from 'native-testing-library';
4+
import { render } from '../../src';
55

66
let idCounter = 1;
77

examples/__tests__/use-hooks.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { useState } from 'react';
2+
import { renderHook, act } from 'react-hooks-testing-library';
3+
4+
describe('useState tests', () => {
5+
test('should use setState value', () => {
6+
const { result } = renderHook(() => useState('foo'));
7+
const [value] = result.current;
8+
9+
expect(value).toBe('foo');
10+
});
11+
12+
test('should update setState value using setter', () => {
13+
const { result } = renderHook(() => useState('foo'));
14+
const [_, setValue] = result.current;
15+
16+
act(() => setValue('bar'));
17+
18+
const [value] = result.current;
19+
expect(value).toBe('bar');
20+
});
21+
});

examples/jest.config.js

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

jest-preset.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const jestPreset = require('react-native/jest-preset');
2+
3+
module.exports = Object.assign(jestPreset, {
4+
transformIgnorePatterns: ['node_modules/(?!(react-native.*|@?react-navigation.*)/)'],
5+
setupFiles: [...jestPreset.setupFiles, require.resolve('./src/preset/setup.js')],
6+
});

0 commit comments

Comments
 (0)