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

Commit 27dd1ac

Browse files
author
Brandon Carroll
committed
feat: change the mocked core components
1 parent 49f2b0d commit 27dd1ac

Some content is hidden

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

88 files changed

+1045
-750
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/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+
});

jest.config.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
const jestPreset = require('./jest-preset');
2+
13
const ignores = ['/node_modules/', '/__tests__/helpers/', '__mocks__'];
24

3-
module.exports = {
4-
preset: 'react-native',
5-
transformIgnorePatterns: ['node_modules/(?!(react-native.*|@?react-navigation.*)/)'],
6-
collectCoverageFrom: ['src/**/*.+(js|jsx|ts|tsx)'],
7-
testMatch: ['**/__tests__/**/*.+(js|jsx|ts|tsx)'],
5+
module.exports = Object.assign(jestPreset, {
6+
collectCoverageFrom: ['src/lib/**/*.+(js|jsx|ts|tsx)'],
87
testPathIgnorePatterns: [...ignores],
98
coverageThreshold: {
109
global: {
@@ -14,4 +13,4 @@ module.exports = {
1413
statements: 100,
1514
},
1615
},
17-
};
16+
});

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
77
"files": [
8-
"dist/**"
8+
"dist/**",
9+
"jest-preset.js"
910
],
1011
"engines": {
1112
"node": ">=8"
@@ -16,8 +17,8 @@
1617
"commit:all": "npm run commit:add && npm run commit",
1718
"readme:toc": "doctoc README.md --maxlevel 3 --title '## Table of Contents'",
1819
"test": "jest",
19-
"pretty-quick": "pretty-quick --staged --pattern '**/*.(js|jsx|ts|tsx)'",
20-
"prepublish": "rm -rf dist; babel src --out-dir dist --ignore 'src/__tests__/*' && cp src/index.d.ts dist/index.d.ts",
20+
"pretty-quick": "pretty-quick --staged",
21+
"prepublishOnly": "rm -rf dist; babel src --out-dir dist --ignore 'src/**/__tests__/*'",
2122
"semantic-release": "semantic-release",
2223
"test:coverage": "jest --coverage",
2324
"test:watch": "jest --watch --coverage"
@@ -35,6 +36,7 @@
3536
"author": "Brandon Carroll <[email protected]> (https://github.com/bcarroll22)",
3637
"license": "MIT",
3738
"dependencies": {
39+
"jest-native": "2.0.0-alpha.5",
3840
"pretty-format": "^24.5.0",
3941
"react-test-renderer": "^16.8.5",
4042
"wait-for-expect": "^1.1.1"
@@ -50,7 +52,6 @@
5052
"jest": "24.5.0",
5153
"jest-fetch-mock": "^2.1.1",
5254
"jest-in-case": "^1.0.2",
53-
"jest-native": "^1.2.0",
5455
"metro-react-native-babel-preset": "^0.52.0",
5556
"prettier": "^1.16.4",
5657
"pretty-quick": "^1.10.0",
@@ -61,7 +62,6 @@
6162
"react-native-gesture-handler": "^1.1.0",
6263
"react-navigation": "^3.5.1",
6364
"react-redux": "6.0.1",
64-
"react-test-renderer-tree-to-json": "^1.0.1",
6565
"redux": "^4.0.0",
6666
"semantic-release": "^15.13.3"
6767
},

setup.js

Whitespace-only changes.

src/__tests__/__snapshots__/fetch.js.snap

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

src/__tests__/filter.js

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

src/__tests__/misc.js

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

src/__tests__/query-helpers.js

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

0 commit comments

Comments
 (0)