* feat: add "cleanup" function
* docs: add "cleanup" section
* feat: automatically call "cleanup" after each test
...if an "afterEach" global function is defined, and process.env.RTL_SKIP_AUTO_CLEANUP is falsy.
Taken from: https://github.com/testing-library/react-testing-library/blob/14670debd45236d2c5d0a61a83dadc72af1bef7c/src/index.js
* docs: mention automatic cleanup
* add within
* fix lint
* Updated tests, added auto-cleanup test
* Added ways to prevent auto cleanup
* Small fix
* Code review changes
* Update website/docs/API.md
Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
* More changes
* Removed afterEach(cleanup) calls in examples
* Code cleanup
Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
Co-authored-by: Maciej Jastrzebski <mdjastrzebski@gmail.com>
* Replaced getByTestId with fixed version
* Added tests
* Fixed flow-check
* Updated docs
* Fixed lint error
* Used getByTestId in unit tests instead of queryByTestId
* Updated negative checks in tests
* Added @testing-library/jest-native to devDependencies
* Tests for jest-native matchers
* Added @testing-library/jest-native install info
* Update README.md
* Update GettingStarted.md
* feat: add `findBy*` queries (#304)
* Basic async findBy queries
* Refactored findBy queries to be built with makeFindQuery
* findBy queries for A11y selectors
* Custom findByTestId implementation that avoids current getByTestId issues
* Fixed prettier issue
* Updates Queries.md with findBy queries
* Trying to fix test timeout error appearing only on CI
* Code review changes
* Added typescript types & tests
* prettier did reformat some code arround
* Removed export of GetByAPI, QueryByAPI and FindByAPI interfaces in TS
* Reversed prettier run on typings
* Added overlapping pieces with `within` operator
* Small cleanup
* Update website/docs/Queries.md
* Moved async/await tests to the end of test methods
Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
* chore: bump eslint config to latest (#308)
* chore: bump eslint config to latest
* lint fix
* lint pass
* use roles directly
* Trying to fix CI build
* Added $FlowFixMe for missing flow expect extensions
* Small doc fixes
* Clarified failing toHaveProps matcher tests
* Moved lint ignore for color literals to .eslintrc
* Updated toHaveProp tests to avoid strange `Button` behavior
* Updated yarn.lock
* Update README.md
* Update website/docs/GettingStarted.md
Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
* Basic async findBy queries
* Refactored findBy queries to be built with makeFindQuery
* findBy queries for A11y selectors
* Custom findByTestId implementation that avoids current getByTestId issues
* Fixed prettier issue
* Updates Queries.md with findBy queries
* Trying to fix test timeout error appearing only on CI
* Code review changes
* Added typescript types & tests
* prettier did reformat some code arround
* Removed export of GetByAPI, QueryByAPI and FindByAPI interfaces in TS
* Reversed prettier run on typings
* Added overlapping pieces with `within` operator
* Small cleanup
* Update website/docs/Queries.md
* Moved async/await tests to the end of test methods
Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
* feat: query nested text nodes
* test on nested text nodes
* test on custom component, refactor
* remove comments
* move textContent out of module scope, fixup children check
Co-authored-by: Mariia Marchenkova <marchewka@Mariias-MacBook-Pro.local>
Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
* feat: add getAllByTestId and queryAllByTestId queries
* Add test for getAllByTestId and queryAllByTestId
- Filter out intermediate components in getAllByTestId. testIDs may be passed down to child components and appearing multiple times in the render tree. Some React Native components render multiple anyways. <Text> is an example.
* Update TypeScript typings
* Fix flow types
* Update TS typings test
### Summary
Bumping Jest to latest, removed inline snapshot as there's a pending bug with trailing whitespaces inside of it being removed by IDEs (solution is to make them regular snapshots, but in this case the test was just plain unnecessary)
### Test plan
CI
<!-- 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
### Summary
If I have a custom button like:
```js
<MyCustomButton handlePress={onPress} />
```
The following will not work:
```js
fireEvent(getByTestId('my-custom-button'), 'handlePress');
```
Because we are trying to call `onHandlePress`.
### Test plan
```
yarn test fireEvent
```
### 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).
### Summary
Check for undefined/null values, in `getByText` nodes.
Fixes#135
### Test plan
Passing tests on repro repository https://github.com/wKovacs64/rntl-161-repro.
Have no idea how to create a unit test, to test this behavior.
cc @thymikee @wKovacs64
### 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!
### 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
<!-- Please provide enough information so that others can review your pull request. -->
<!-- Keep pull requests small and focused on a single change. -->
### Summary
Existential type (`*`) is long deprecated, let's just use `any` for now.
### Test plan
Added some more Flow typings to `shallow.test.js` that were failing because of existential type.