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

Commit 1f0fb6d

Browse files
author
Brandon Carroll
committed
alpha 0
1 parent 2758953 commit 1f0fb6d

19 files changed

+74
-221
lines changed

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.config.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
const ignores = ['/node_modules/', '/__tests__/helpers/', '__mocks__'];
22

33
module.exports = {
4-
preset: 'react-native',
5-
transformIgnorePatterns: ['node_modules/(?!(react-native.*|@?react-navigation.*)/)'],
4+
preset: 'jest-native',
65
collectCoverageFrom: ['src/**/*.+(js|jsx|ts|tsx)'],
7-
testMatch: ['**/__tests__/**/*.+(js|jsx|ts|tsx)'],
86
testPathIgnorePatterns: [...ignores],
97
coverageThreshold: {
108
global: {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"commit:all": "npm run commit:add && npm run commit",
1717
"readme:toc": "doctoc README.md --maxlevel 3 --title '## Table of Contents'",
1818
"test": "jest",
19-
"pretty-quick": "pretty-quick --staged --pattern '**/*.(js|jsx|ts|tsx)'",
19+
"pretty-quick": "pretty-quick --staged",
2020
"prepublish": "rm -rf dist; babel src --out-dir dist --ignore 'src/__tests__/*' && cp src/index.d.ts dist/index.d.ts",
2121
"semantic-release": "semantic-release",
2222
"test:coverage": "jest --coverage",
@@ -35,6 +35,7 @@
3535
"author": "Brandon Carroll <brandonvcarroll@gmail.com> (https://github.com/bcarroll22)",
3636
"license": "MIT",
3737
"dependencies": {
38+
"jest-native": "2.0.0-alpha.5",
3839
"pretty-format": "^24.5.0",
3940
"react-test-renderer": "^16.8.5",
4041
"wait-for-expect": "^1.1.1"
@@ -50,7 +51,6 @@
5051
"jest": "24.5.0",
5152
"jest-fetch-mock": "^2.1.1",
5253
"jest-in-case": "^1.0.2",
53-
"jest-native": "^1.2.0",
5454
"metro-react-native-babel-preset": "^0.52.0",
5555
"prettier": "^1.16.4",
5656
"pretty-quick": "^1.10.0",

src/__tests__/__snapshots__/fetch.js.snap

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,14 @@
22

33
exports[`Fetch makes an API call and displays the greeting when load-greeting is clicked 1`] = `
44
<View>
5-
<View
6-
accessible={true}
7-
isTVSelectable={true}
8-
onResponderGrant={[Function]}
9-
onResponderMove={[Function]}
10-
onResponderRelease={[Function]}
11-
onResponderTerminate={[Function]}
12-
onResponderTerminationRequest={[Function]}
13-
onStartShouldSetResponder={[Function]}
14-
style={
15-
Object {
16-
"opacity": 1,
17-
}
18-
}
5+
<TouchableOpacity
6+
activeOpacity={0.2}
7+
onPress={[Function]}
198
>
209
<Text>
2110
Fetch
2211
</Text>
23-
</View>
12+
</TouchableOpacity>
2413
<Text>
2514
hello there
2615
</Text>

src/__tests__/act.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ test('fireEvent triggers useEffect calls', () => {
2222
const [count, setCount] = React.useState(0);
2323
return <Button onPress={() => setCount(count + 1)} title={`${count}`} />;
2424
}
25-
const { getByText } = render(<Counter />);
26-
const buttonNode = getByText('0');
25+
const { getByTitle } = render(<Counter />);
26+
const buttonNode = getByTitle('0');
2727
effectCb.mockClear();
2828
fireEvent.press(buttonNode);
29-
expect(buttonNode).toHaveTextContent('1');
29+
expect(buttonNode.props.title).toBe('1');
3030
expect(effectCb).toHaveBeenCalledTimes(1);
3131
});
3232

src/__tests__/forms.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ function Login({ onSubmit, user }) {
2525
test('login form submits', () => {
2626
const fakeUser = { username: 'bcarroll', password: 'starboy' };
2727
const handleSubmit = jest.fn();
28-
const { getByText } = render(<Login onSubmit={handleSubmit} user={fakeUser} />);
28+
const { getByTitle } = render(<Login onSubmit={handleSubmit} user={fakeUser} />);
2929

30-
const submitButtonNode = getByText('Submit');
30+
const submitButtonNode = getByTitle('Submit');
3131

3232
fireEvent.press(submitButtonNode);
3333

src/__tests__/pretty-print.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import { render } from '../';
55
import { prettyPrint } from '../pretty-print';
66

77
test('it prints correctly with no children', () => {
8-
const { baseElement } = render(<View />);
8+
const { container } = render(<View />);
99

10-
expect(prettyPrint(baseElement)).toMatchInlineSnapshot(`"[36m<View />[39m"`);
10+
expect(prettyPrint(container.toJSON())).toMatchInlineSnapshot(`"[36m<View />[39m"`);
1111
});
1212

1313
test('it prints correctly with one child', () => {
14-
const { baseElement } = render(
14+
const { container } = render(
1515
<View>
1616
<Text>Hello World!</Text>
1717
</View>,
1818
);
1919

20-
expect(prettyPrint(baseElement)).toMatchInlineSnapshot(`
20+
expect(prettyPrint(container.toJSON())).toMatchInlineSnapshot(`
2121
"<View>
2222
<Text>
2323
Hello World!
@@ -27,14 +27,14 @@ test('it prints correctly with one child', () => {
2727
});
2828

2929
test('it prints correctly with multiple children', () => {
30-
const { baseElement } = render(
30+
const { container } = render(
3131
<View>
3232
<Text>Hello</Text>
3333
<Text>World!</Text>
3434
</View>,
3535
);
3636

37-
expect(prettyPrint(baseElement)).toMatchInlineSnapshot(`
37+
expect(prettyPrint(container.toJSON())).toMatchInlineSnapshot(`
3838
"<View>
3939
<Text>
4040
Hello
@@ -47,11 +47,11 @@ test('it prints correctly with multiple children', () => {
4747
});
4848

4949
test('it supports truncating the output length', () => {
50-
const { baseElement } = render(
50+
const { container } = render(
5151
<View>
5252
<Text>Hello World!</Text>
5353
</View>,
5454
);
5555

56-
expect(prettyPrint(baseElement, 5)).toMatch(/\.\.\./);
56+
expect(prettyPrint(container.toJSON(), 5)).toMatch(/\.\.\./);
5757
});

src/__tests__/stopwatch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ const wait = time => new Promise(resolve => setTimeout(resolve, time));
4141

4242
test('unmounts a component', async () => {
4343
jest.spyOn(console, 'error').mockImplementation(() => {});
44-
const { unmount, getByText, container } = render(<StopWatch />);
45-
fireEvent.press(getByText('Start'));
44+
const { unmount, getByTitle, container } = render(<StopWatch />);
45+
fireEvent.press(getByTitle('Start'));
4646

4747
unmount();
4848

src/core-components.js

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

0 commit comments

Comments
 (0)