13 Commits

Author SHA1 Message Date
Scotty Waggoner f6f0a7091d feat: Add wrapper option to render (#173)
* Add wrapper option to render

* Update TS types and call updateWithAct only once

* wrapUiIfNeeded -> wrap

* reindent snapshots

* adjustments

* change name
2019-05-28 22:31:48 +02:00
Kacper Wiszczuk 7a1c264bb0 Docs: Remove shallow API from docs (#154) 2019-04-14 17:39:11 +02:00
Michał Pierzchała e8a817cae4 docs: add and update queries documentation (#151)
### Summary

Adds new "Queries" section inspired by https://testing-library.com/docs/dom-testing-library/api-queries

### Test plan

Reading carefully
2019-04-14 16:12:50 +02:00
Michał Pierzchała 439db6c823 feat: add rerender as an alias for update (#149)
<!-- Please provide enough information so that others can review your pull request. -->
<!-- Keep pull requests small and focused on a single change. -->

### Summary

Users of `react-testing-library` use `rerender` wording instead of `update`. Let's make it easier for them by aliasing it.
See: https://testing-library.com/docs/react-testing-library/api#rerender

### Test plan

Added cases for JS tests and TS typings
2019-04-14 10:09:46 +02:00
Jean-Marie Porchet 859e29c569 docs: provide example for componentDidMount (#144)
### Summary
Some people find it useful to search for specific terms when browsing the docs.
Specifying the concrete utility of the `update` method makes the doc more useful :)
2019-04-01 16:39:01 +02:00
Brad f96d782d26 Improvement: Add act to update call to support hooks (#137)
### Summary
Currently `render` and `fireEvent` are wrapped in `act` to support hooks. This pull request wraps the update call in `act` to support testing component updates (e.g. prop changes).

### Test plan
* I have added a test for update in `__tests__/act.test.js`.
* A useEffect hook should run again on `update` calls (if the hook dependency array is satisfied).
2019-03-25 15:22:34 +01:00
Eli Perkins 97ab842567 improvement: Allow for text to match children who are composed as array (#132)
### Summary

Given a component that renders text by composing together literal text with an inline expression for a dynamic variable, React Native will render this as a `<Text>` element with multiple children. For example:

```js
const BananaCounter = ({ numBananas }) => (
  <Text>There are {numBananas} bananas in the bunch</Text>
);

const { toJSON, debug } = render(<BananaCounter numBananas={3} />);

debug();
/*
      <Text>
        There are
        3
         bananas in the bunch
      </Text>
*/

expect(toJSON()).toMatchInlineSnapshot(`
<Text>
  There are 
  3
   bananas in the bunch
</Text>
`);
```

This makes sense, as the component is a:
- literal string
- a dynamic evaluation
- literal string

Unfortunately, this means that writing a test that finds an element based on that dynamic evaluation fails when using `getByText`.

```js

const { getByText } = render(<BananaCounter numBananas={3} />);
expect(getByText('There are 3 bananas in the bunch')).toBeTruthy(); // Fails
```

This is because we compare the given test string directly against `children`. https://github.com/callstack/react-native-testing-library/blob/ce3bf28f308728672bc5502e120048821c60218b/src/helpers/getByAPI.js#L23-L24

This results in comparing `'There are 3 bananas in the bunch' === ['There are ' 3, ' bananas in the bunch']`, which of course will fail.

The solution is to join children and compare the joined result against the given text string.

### Test plan

A test for this new functionality is provided!
2019-03-18 16:25:13 +01:00
Ingibjörg Ósk Jónsdóttir (Inga) 09f9b9f05a docs: Remove misleading recommendation to use shallow in snapshot tests (#128)
### Summary

I removed misleading recommendation to render components with `shallow` in snapshot tests as a result of the conversation in Issue #127.

### Test plan

Review text in API.md
2019-03-07 20:55:03 +01:00
Kacper Wiszczuk 11489b0e5e feat: wrap render with act() for better React Hooks support (#122) 2019-02-28 21:53:26 +01:00
Enieber Cunha 39d2e7c8d0 chore: add links to more sample of code (#104)
* add links to more sample of code

* Update API.md

* Update API.md
2019-01-15 17:25:28 +01:00
Dana Hartweg af067d0712 docs: Add more details to the fireEvent api documentation. (#102) 2018-12-28 11:51:35 +01:00
Dana Hartweg ee888f1dcd feat: add getByPlaceholder query functionality (#101)
### Summary
There is a helper that exists in `react-testing-library` to query inputs by their `placeholder`. This PR adds that support.

You **could** achieve this by querying for a `placeholder` prop, or querying for react native `TextInput`s manually and then checking their props, but it felt cleaner to have this contained in the testing library itself. It will also allow you to bypass any other instances that may have a `placeholder` prop that aren't `TextInput`s.

If we don't want to expand the surface of the library further, I completely understand that and am fine with this being closed. Just seems like it may be useful and save some time for several scenarios =)

### Test plan
+ Render a `TextInput` with a `placeholder` prop
+ Query the test instance via `getByPlaceholder` for the input
+ Verify the test instance is found
2018-12-22 23:09:28 +01:00
Michał Pierzchała 53b5366393 docs: Rename api.md to API.md (#94)
<!-- Please provide enough information so that others can review your pull request. -->
<!-- Keep pull requests small and focused on a single change. -->

### Summary

Whoopsie

### Test plan

<!-- List the steps with which we can test this change. Provide screenshots if this changes anything visual. -->
2018-12-15 12:34:19 +01:00