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

Commit d82bfde

Browse files
committed
Merge branch 'next'
2 parents 64d8a20 + 6aea9a7 commit d82bfde

File tree

110 files changed

+2425
-2087
lines changed

Some content is hidden

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

110 files changed

+2425
-2087
lines changed

.all-contributorsrc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"projectName": "native-testing-library",
3-
"projectOwner": "bcarroll22",
3+
"projectOwner": "testing-library",
44
"repoType": "github",
55
"files": [
66
"README.md"
@@ -68,6 +68,15 @@
6868
"contributions": [
6969
"doc"
7070
]
71+
},
72+
{
73+
"login": "elyalvarado",
74+
"name": "Ely Alvarado",
75+
"avatar_url": "https://avatars1.githubusercontent.com/u/545352?v=4",
76+
"profile": "https://github.com/elyalvarado",
77+
"contributions": [
78+
"code"
79+
]
7180
}
7281
],
7382
"contributorsPerLine": 7,

.github/ISSUE_TEMPLATE/Bug_Report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ We'll probably ask you to submit the fix (after giving some direction). If you'v
1414

1515
- `react-native` or `expo`:
1616
- `native-testing-library` version:
17+
- `jest-preset`:
1718
- `react-native` version:
1819
- `node` version:
19-
- `npm` (or `yarn`) version:
2020

2121
### Relevant code or config:
2222

.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

README.md

Lines changed: 38 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,30 @@
66
height="80"
77
width="80"
88
alt="goat"
9-
src="https://github.com/raw/bcarroll22/native-testing-library/master/other/whale.png"
9+
src="https://github.com/raw/testing-library/native-testing-library/master/other/whale.png"
1010
/>
1111
</a>
1212

1313
<p>Simple and complete React Native testing utilities that encourage good testing practices.</p>
1414

1515
[**Read The Docs**](https://native-testing-library.com/docs/intro) |
16-
[Edit the docs](https://github.com/bcarroll22/native-testing-library-docs)
16+
[Edit the docs](https://github.com/testing-library/native-testing-library-docs)
1717
</div>
1818

1919
<hr />
2020

21-
[![Build Status](https://travis-ci.org/bcarroll22/native-testing-library.svg?branch=master)](https://travis-ci.org/bcarroll22/native-testing-library)
22-
[![Code Coverage](https://img.shields.io/codecov/c/github/bcarroll22/native-testing-library.svg?style=flat-square)](https://codecov.io/github/bcarroll22/native-testing-library)
21+
[![Build Status](https://travis-ci.org/testing-library/native-testing-library.svg?branch=master)](https://travis-ci.org/testing-library/native-testing-library)
22+
[![Code Coverage](https://img.shields.io/codecov/c/github/testing-library/native-testing-library.svg?style=flat-square)](https://codecov.io/github/testing-library/native-testing-library)
2323
[![version](https://img.shields.io/npm/v/native-testing-library.svg?style=flat-square)](https://www.npmjs.com/package/native-testing-library)
2424
[![downloads](https://img.shields.io/npm/dm/native-testing-library.svg?style=flat-square)](http://www.npmtrends.com/native-testing-library)
25-
[![MIT License](https://img.shields.io/npm/l/native-testing-library.svg?style=flat-square)](https://github.com/bcarroll22/native-testing-library/blob/master/LICENSE)
25+
[![MIT License](https://img.shields.io/npm/l/native-testing-library.svg?style=flat-square)](https://github.com/testing-library/native-testing-library/blob/master/LICENSE)
2626

27-
[![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors)
27+
[![All Contributors](https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square)](#contributors)
2828
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
29-
[![Code of Conduct](https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square)](https://github.com/bcarroll22/native-testing-library/blob/master/CODE_OF_CONDUCT.md)
29+
[![Code of Conduct](https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square)](https://github.com/testing-library/native-testing-library/blob/master/CODE_OF_CONDUCT.md)
3030

31-
[![Watch on GitHub](https://img.shields.io/github/watchers/bcarroll22/native-testing-library.svg?style=social)](https://github.com/bcarroll22/native-testing-library/watchers)
32-
[![Star on GitHub](https://img.shields.io/github/stars/bcarroll22/native-testing-library.svg?style=social)](https://github.com/bcarroll22/native-testing-library/stargazers)
31+
[![Watch on GitHub](https://img.shields.io/github/watchers/testing-library/native-testing-library.svg?style=social)](https://github.com/testing-library/native-testing-library/watchers)
32+
[![Star on GitHub](https://img.shields.io/github/stars/testing-library/native-testing-library.svg?style=social)](https://github.com/testing-library/native-testing-library/stargazers)
3333

3434
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
3535
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
@@ -39,13 +39,13 @@
3939
- [The problem](#the-problem)
4040
- [This solution](#this-solution)
4141
- [Example](#example)
42-
- [Guiding principles](#guiding-principles)
4342
- [Installation](#installation)
4443
- [Hooks](#hooks)
45-
- [Inspiration](#inspiration)
4644
- [Other Solutions](#other-solutions)
4745
- [Guiding Principles](#guiding-principles)
46+
- [Inspiration](#inspiration)
4847
- [Contributors](#contributors)
48+
- [Docs](#docs)
4949

5050
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
5151

@@ -92,7 +92,7 @@ function Example() {
9292
}
9393

9494
test('examples of some things', async () => {
95-
const { getByTestId, getByText, queryByTestId, rootInstance } = render(<Example />);
95+
const { getByTestId, getByText, queryByTestId } = render(<Example />);
9696
const famousWomanInHistory = 'Ada Lovelace';
9797

9898
const input = getByTestId('input');
@@ -103,33 +103,11 @@ test('examples of some things', async () => {
103103

104104
await wait(() => expect(queryByTestId('printed-username')).toBeTruthy());
105105

106-
expect(getByTestId('printed-username').props.children).toBe(famousWomanInHistory);
106+
expect(getByTestId('printed-username')).toHaveTextContent(famousWomanInHistory);
107107
expect(rootInstance).toMatchSnapshot();
108108
});
109109
```
110110

111-
## Guiding principles
112-
113-
> [The more your tests resemble the way your software is used, the more confidence they can give you.](https://twitter.com/kentcdodds/status/977018512689455106)
114-
115-
We try to only expose methods and utilities that encourage you to write tests that closely resemble
116-
how your apps are used.
117-
118-
Utilities are included in this project based on the following guiding principles:
119-
120-
1. Rendering React Native components ultimately creates native views, and those views should be
121-
what you test rather than the React component instances you rendered to make them.
122-
2. In general, test the way your users use your app. There are instances where you'll need to write
123-
unit tests, but try your best to write with this first -- the more your tests resemble the way
124-
your app works, the more confident you'll be with your app.
125-
3. Be responsible, and remember that testing exists to serve you, not the other way around. If the
126-
library isn't working for you, contribute to make it work or do something more intuitive. Make
127-
your tests work for you and your team!
128-
129-
In summary, we believe in the principles of `dom-testing-library` and its companion libraries, and
130-
try to adhere to them as closely as possible. Changes to this library should always consider how
131-
they relate to what's happening in the other libraries in this family of tools.
132-
133111
## Installation
134112

135113
This module should be installed in your project's `devDependencies`:
@@ -142,34 +120,15 @@ You will need `react` and `react-native` installed as _dependencies_ in order to
142120

143121
## Hooks
144122

145-
You can test hooks out of the box with this package as follows:
146-
147-
```javascript
148-
import { renderHook } from 'native-testing-library';
149-
```
150-
151-
Reads more about hooks on the [docs site](https://native-testing-library.com/docs/api-render-hook).
152-
153-
## Inspiration
154-
155-
Huge thanks to Kent C. Dodds for evangelizing this approach to testing. We could have never come up
156-
with this library without him 🙏. Check out his awesome work and learn more about testing with
157-
confidence at [testingjavascript.com](https://testingjavascript.com/) (you won't regret purchasing
158-
it), and of course, use this library's big brother, `react-testing-library` for your DOM
159-
applications as well!
160-
161-
The hook testing ability of this library is the same implementation as
162-
[react-hooks-testing-library](https://github.com/mpeyper/react-hooks-testing-library). The only
163-
reason it was included in this package is because we need you to import render from us, not the
164-
`dom-testing-library`, and that's an important blocker. Some day, maybe we'll try to allow use of
165-
that library with this one somehow.
123+
If you are interested in testing a custom hook, check out
124+
[react-hooks-testing-library](https://github.com/mpeyper/react-hooks-testing-library).
166125

167126
## Other Solutions
168127

169128
- [`react-native-testing-library`](https://github.com/callstack/react-native-testing-library)
170129
- [`enzyme`](https://airbnb.io/enzyme/docs/guides/react-native.html)
171130

172-
## Guiding Principles
131+
## Guiding principles
173132

174133
> [The more your tests resemble the way your software is used, the more confidence they can give you.](https://twitter.com/kentcdodds/status/977018512689455106)
175134
@@ -190,14 +149,34 @@ In summary, we believe in the principles of `testing-library`, and adhere to the
190149
possible. At the end of the day, what we want is for this library to be pretty light-weight, simple,
191150
and understandable.
192151

152+
## Inspiration
153+
154+
Huge thanks to Kent C. Dodds for evangelizing this approach to testing. We could have never come up
155+
with this library without him 🙏. Check out his awesome work and learn more about testing with
156+
confidence at [testingjavascript.com](https://testingjavascript.com/) (you won't regret purchasing
157+
it), and of course, use this library's big brother, `react-testing-library` for your DOM
158+
applications as well!
159+
160+
The hook testing ability of this library is the same implementation as
161+
[react-hooks-testing-library](https://github.com/mpeyper/react-hooks-testing-library). The only
162+
reason it was included in this package is because we need you to import render from us, not the
163+
`dom-testing-library`, and that's an important blocker. Some day, maybe we'll try to allow use of
164+
that library with this one somehow.
165+
193166
## Contributors
194167

195168
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
196169

197170
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
198171
<!-- prettier-ignore -->
199-
<table><tr><td align="center"><a href="https://github.com/bcarroll22"><img src="https://avatars2.githubusercontent.com/u/11020406?v=4" width="100px;" alt="Brandon Carroll"/><br /><sub><b>Brandon Carroll</b></sub></a><br /><a href="https://github.com/bcarroll22/native-testing-library/commits?author=bcarroll22" title="Code">💻</a> <a href="https://github.com/bcarroll22/native-testing-library/commits?author=bcarroll22" title="Documentation">📖</a> <a href="#infra-bcarroll22" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/bcarroll22/native-testing-library/commits?author=bcarroll22" title="Tests">⚠️</a></td><td align="center"><a href="http://tagraves.com"><img src="https://avatars1.githubusercontent.com/u/2263711?v=4" width="100px;" alt="Tommy Graves"/><br /><sub><b>Tommy Graves</b></sub></a><br /><a href="#ideas-TAGraves" title="Ideas, Planning, & Feedback">🤔</a> <a href="#maintenance-TAGraves" title="Maintenance">🚧</a> <a href="#review-TAGraves" title="Reviewed Pull Requests">👀</a></td><td align="center"><a href="https://kentcdodds.com"><img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;" alt="Kent C. Dodds"/><br /><sub><b>Kent C. Dodds</b></sub></a><br /><a href="#ideas-kentcdodds" title="Ideas, Planning, & Feedback">🤔</a></td><td align="center"><a href="https://github.com/sz-piotr"><img src="https://avatars2.githubusercontent.com/u/17070569?v=4" width="100px;" alt="Piotr Szlachciak"/><br /><sub><b>Piotr Szlachciak</b></sub></a><br /><a href="https://github.com/bcarroll22/native-testing-library/commits?author=sz-piotr" title="Code">💻</a></td><td align="center"><a href="https://github.com/mcgloneleviROOT"><img src="https://avatars3.githubusercontent.com/u/48258981?v=4" width="100px;" alt="mcgloneleviROOT"/><br /><sub><b>mcgloneleviROOT</b></sub></a><br /><a href="https://github.com/bcarroll22/native-testing-library/issues?q=author%3AmcgloneleviROOT" title="Bug reports">🐛</a> <a href="https://github.com/bcarroll22/native-testing-library/commits?author=mcgloneleviROOT" title="Code">💻</a></td><td align="center"><a href="http://exercism.io/profiles/wolverineks/619ce225090a43cb891d2edcbbf50401"><img src="https://avatars2.githubusercontent.com/u/8462274?v=4" width="100px;" alt="Kevin Sullivan"/><br /><sub><b>Kevin Sullivan</b></sub></a><br /><a href="https://github.com/bcarroll22/native-testing-library/commits?author=wolverineks" title="Documentation">📖</a></td></tr></table>
172+
<table><tr><td align="center"><a href="https://github.com/bcarroll22"><img src="https://avatars2.githubusercontent.com/u/11020406?v=4" width="100px;" alt="Brandon Carroll"/><br /><sub><b>Brandon Carroll</b></sub></a><br /><a href="https://github.com/testing-library/native-testing-library/commits?author=bcarroll22" title="Code">💻</a> <a href="https://github.com/testing-library/native-testing-library/commits?author=bcarroll22" title="Documentation">📖</a> <a href="#infra-bcarroll22" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/testing-library/native-testing-library/commits?author=bcarroll22" title="Tests">⚠️</a></td><td align="center"><a href="http://tagraves.com"><img src="https://avatars1.githubusercontent.com/u/2263711?v=4" width="100px;" alt="Tommy Graves"/><br /><sub><b>Tommy Graves</b></sub></a><br /><a href="#ideas-TAGraves" title="Ideas, Planning, & Feedback">🤔</a> <a href="#maintenance-TAGraves" title="Maintenance">🚧</a> <a href="#review-TAGraves" title="Reviewed Pull Requests">👀</a></td><td align="center"><a href="https://kentcdodds.com"><img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;" alt="Kent C. Dodds"/><br /><sub><b>Kent C. Dodds</b></sub></a><br /><a href="#ideas-kentcdodds" title="Ideas, Planning, & Feedback">🤔</a></td><td align="center"><a href="https://github.com/sz-piotr"><img src="https://avatars2.githubusercontent.com/u/17070569?v=4" width="100px;" alt="Piotr Szlachciak"/><br /><sub><b>Piotr Szlachciak</b></sub></a><br /><a href="https://github.com/testing-library/native-testing-library/commits?author=sz-piotr" title="Code">💻</a></td><td align="center"><a href="https://github.com/mcgloneleviROOT"><img src="https://avatars3.githubusercontent.com/u/48258981?v=4" width="100px;" alt="mcgloneleviROOT"/><br /><sub><b>mcgloneleviROOT</b></sub></a><br /><a href="https://github.com/testing-library/native-testing-library/issues?q=author%3AmcgloneleviROOT" title="Bug reports">🐛</a> <a href="https://github.com/testing-library/native-testing-library/commits?author=mcgloneleviROOT" title="Code">💻</a></td><td align="center"><a href="http://exercism.io/profiles/wolverineks/619ce225090a43cb891d2edcbbf50401"><img src="https://avatars2.githubusercontent.com/u/8462274?v=4" width="100px;" alt="Kevin Sullivan"/><br /><sub><b>Kevin Sullivan</b></sub></a><br /><a href="https://github.com/testing-library/native-testing-library/commits?author=wolverineks" title="Documentation">📖</a></td><td align="center"><a href="https://github.com/elyalvarado"><img src="https://avatars1.githubusercontent.com/u/545352?v=4" width="100px;" alt="Ely Alvarado"/><br /><sub><b>Ely Alvarado</b></sub></a><br /><a href="https://github.com/testing-library/native-testing-library/commits?author=elyalvarado" title="Code">💻</a></td></tr></table>
200173

201174
<!-- ALL-CONTRIBUTORS-LIST:END -->
202175

203-
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
176+
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors)
177+
specification. Contributions of any kind welcome!
178+
179+
## Docs
180+
181+
[**Read The Docs**](https://native-testing-library.com) |
182+
[Edit the docs](https://github.com/testing-library/native-testing-library-docs)

babel.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
module.exports = {
22
presets: ['module:metro-react-native-babel-preset'],
3+
overrides: [
4+
{
5+
compact: false,
6+
},
7+
],
38
};

examples/__tests__/input-event.js

Lines changed: 3 additions & 3 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 = {
@@ -29,7 +29,7 @@ class CostInput extends React.Component {
2929

3030
const setup = () => {
3131
const utils = render(<CostInput />);
32-
const input = utils.getByA11yLabel('cost-input');
32+
const input = utils.getByLabelText('cost-input');
3333
return {
3434
input,
3535
...utils,

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 />), navigationTestRenderer: 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');

0 commit comments

Comments
 (0)