78 Commits

Author SHA1 Message Date
Michał Pierzchała 111b1c9277 fix: modern jest timers (#397)
* fix: modern jest timers

* treat modern timers as default, but be explicit in tests

* we're node-only

* rename to Thenable

* add clarifications; unify test names

* Update src/__tests__/auto-cleanup-skip.test.js

Co-authored-by: Maciej Jastrzebski <mdjastrzebski@gmail.com>

Co-authored-by: Maciej Jastrzebski <mdjastrzebski@gmail.com>
2020-07-10 16:18:31 +02:00
Michał Pierzchała 362d3727bf chore: bump Jest typings (#396) 2020-06-22 10:55:04 +02:00
Maciej Jastrzebski 300d16b822 feature: wait for element to be removed (#376)
* feature: basic implementation

* feature: basic implementation

* feature: added typescript types

* feature: check if element exists initially

* resolve promise with initial elements

* docs: README & API

* use ErrorWithStack helper

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
2020-06-10 08:17:01 +02:00
Maciej Jastrzebski 2b14360f28 feat: wrap waitFor in (async) act to support async queries without explicit act call (#344)
* Wrapped waitFor call in act to support async waitFor/findBy

* Updated docs

* Spelling mistake

* Added short info in migration guide

* Corrected spelling

* Clarified comments

* Added async act implementation conditional on React version

* Code review changes

* Update src/waitFor.js

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>

* Update src/waitFor.js

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>

* Fixed prettier

* Update src/waitFor.js

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
2020-05-28 15:06:04 +02:00
Maciej Jastrzebski 9e50bff6ab chore(breaking): deprecate flushMicrotasksQueue (#340)
* Deprecated flushMicrotasksQueue

* Update website/docs/Migration20.md

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>

* Renamed flushMicrotasksQueueInternal to flushMicroTasks

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
2020-05-28 15:06:04 +02:00
Alec Larson ad66a5489d feat: call "cleanup" automatically (#238)
* 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>
2020-05-28 15:06:04 +02:00
Maciej Jastrzebski 01bc0ee2b4 feat: update docs bases on cancelled prepare-2 PR (#335)
* Adapt docs changes from `prepare-2` branch

* WIP

* Removed unused `printUnsafeWarning` function

# Conflicts:
#	src/helpers/errors.js

* Code review changes
2020-05-28 15:06:04 +02:00
Maciej Jastrzebski 9fc83fec60 Feat(breaking): remove deprecated functions (#334)
* WIP

* More changes

* WIP

* Added throwRemovedFunctionError docsRef

* Fixed tests

* Typescript types cleanup

* Cleanup

* Moving some changes from `prepare-2` branch

* Moving some changes from `prepare-2` branch

* Update src/waitFor.js

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>

* Update website/docs/Migration20.md

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>

* Code review changes

* More code review changes

* Code review changes

* More code review changes

* Added @deprecated messages for TS type defs

* Spelling mistake

* Reformatted index.d.ts

* Removed remaining refs to warnFn

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
2020-05-28 15:06:04 +02:00
Maciej Jastrzebski 5e798bc2e3 Feat(breaking): unify wait for element signature with testing library (#327)
* Change argument to options object

* Renamed `waitForElement` to `waitFor`

* Migration guide entry

* Fixed typescript check

* Update src/helpers/a11yAPI.js

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>

* (Nearly) Empty migration doc for ver. 2.0 (#326)

* Added migration docs section

* Added to docosaurus side bar

* Updated README

* Increased async test timeout

* Update website/docs/Migration20.md

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>

* feat(breaking): remove legacy `debug` export (#328)

* Removed global `debug` functions

* Removed global `debug` from docs

* Cleanup

* Added migration section

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
2020-05-28 15:06:04 +02:00
Maciej Jastrzebski 043f51d36c feat(breaking): remove legacy debug export (#328)
* Removed global `debug` functions

* Removed global `debug` from docs

* Cleanup

* Added migration section

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
2020-05-28 15:06:04 +02:00
Maciej Jastrzebski b3e5ca386c (Nearly) Empty migration doc for ver. 2.0 (#326)
* Added migration docs section

* Added to docosaurus side bar

* Updated README

* Increased async test timeout

* Update website/docs/Migration20.md

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
2020-05-28 15:06:04 +02:00
Maciej Jastrzebski 9b90d6790d fix(breaking): getByTestId should work only for native elements (#324)
* 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
2020-05-28 15:06:04 +02:00
Maciej Jastrzebski 414f8701a5 feat: Support for @testing-library/jest-native (#310)
* 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>
2020-05-18 09:37:59 +02:00
Michał Pierzchała 29ce4f2b48 chore: bump eslint config to latest (#308)
* chore: bump eslint config to latest

* lint fix

* lint pass

* use roles directly
2020-05-15 10:10:49 +02:00
Maciej Jastrzebski ab34712133 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>
2020-05-15 09:52:33 +02:00
Maciej Jastrzebski 1809825313 feat: add within operator for returned instance-bound queries (#306)
* Basic within implementation and tests

* Added typescript types & tests

* Removed duplicated import in index.d.ts

* Reversed prettier run on typings

* Fixed package level exports for `within` operator

* Replaced getByTestId queries with getByA11yHint queries in unit tests for `within`

* Added `within` section to API.md

* Updated README.md regarding `within` operator

* Update website/docs/API.md

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
2020-05-14 12:51:19 +02:00
Maria Marchenkova c8395ef947 feat: query nested text nodes (#293)
* 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>
2020-05-11 19:13:15 +02:00
Kenneth Kwakye-Gyamfi 3e125d20f4 Remove use of getByTestID in documentation and tests (#294)
* Switched most tests from using test IDs

* Docs updated to use alternatives
2020-05-08 16:37:28 +02:00
Jeroen Vannevel 83b28b227d fix: *ByText would call toString() on objects and only match on [object Object] (#290) 2020-05-01 13:54:12 +02:00
Michał Pierzchała 61a83e9bb7 chore: update GettingStarted example with something you can run (#284) 2020-04-23 16:27:01 +02:00
Michał Pierzchała d8fd1543e4 chore: bump RN to 0.62 (#273)
* chore: bump RN to 0.62

* disable accessibilityStates tests; fixups
2020-04-20 11:40:09 +02:00
Kacper Wiszczuk b67227d4b4 chore: lib upgrades (#268)
* Update libs

* Upgrade Typescript

* use flowconfig from 0.61

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
2020-03-18 20:00:31 +01:00
Kacper Wiszczuk 6d31da215d imp: Deprecate shallow (#264) 2020-03-18 13:03:21 +01:00
Kacper Wiszczuk 9edcd16c72 feat: byA11yValue matcher (#262) 2020-03-18 10:42:20 +01:00
Kacper Wiszczuk 960080d210 imp: Re-alias deprecated matchers and warn (#261)
* imp: Re-alias deprecated matchers

* Prepare for byName deletion
2020-03-18 10:30:41 +01:00
Kacper Wiszczuk 62cda2205b feat: byA11yState matcher (#260)
* feat: byA11yState matcher

* Kick CI

* Update src/helpers/a11yAPI.js

Co-Authored-By: Michał Pierzchała <thymikee@gmail.com>

* Correct types

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
2020-03-18 10:06:31 +01:00
Hugo Duprat 0840d44aee fix: (getByText) more robust null/undefined check for text children (#239)
* fix: (getNodeByText) explicitly check if child is undefined or null

* test: Update getByText test cases
2020-01-09 19:59:29 +01:00
Michał Pierzchała 94ff42527e chore: bump Flow and ESLint preset (#241)
* chore: bump Flow and ESLint preset

* fix name of waitForElement
2019-12-09 11:43:05 +01:00
Alec Larson 4c77f4a7dc feat: add "cleanup" function (#237)
* feat: add "cleanup" function

* docs: add "cleanup" section

* test: "cleanup" function

* don't expose cleanup queue


Co-authored-by: Alec Larson <alec.stanford.larson@gmail.com>
Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
2019-12-09 11:41:48 +01:00
Kacper Wiszczuk d216b108b9 fix: correct Flow and TS typings for a11y queries (#205) 2019-07-17 12:10:22 +02:00
Michał Pierzchała 1382a3d7f6 chore: bump React Native to 0.60 (#204) 2019-07-16 18:14:42 +02:00
Kacper Wiszczuk 31f476bb7c feat: support multiple params in event handlers (#203) 2019-07-16 16:19:59 +02:00
Scotty Waggoner fead652013 feat: add getAllByTestId and queryAllByTestId queries (#198)
* 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
2019-07-03 10:17:32 +02:00
Michał Pierzchała a56501b0fb feat: implement ByDisplayValue queries (#190) 2019-06-10 17:30:27 +02:00
Michał Pierzchała 37a5ca573f fix: display correct error frame when fireEvent fails (#184)
* feat: support 'disabled' prop

* revert disabled handling
2019-05-30 12:21:35 +02:00
greenkeeper[bot] 2c181b844e Update flow-bin to the latest version 🚀 (#183)
* chore(package): update flow-bin to version 0.99.0

* chore(package): update lockfile yarn.lock

* Fix flow
2019-05-29 09:13:59 +02:00
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 f9bc0b263d feat: add a11y queries (#178)
* First implementation of matcher generator

* A11y queries added

* extract prepareErrorMessage

* Add tests

* Make aliases

* Move create queryByError

* Add missing aliases

* simplify valid node check

* add docs

* fix types
2019-05-28 20:47:06 +02:00
Michał Pierzchała 1938a5091e chore: bump Jest, remove flaky inline snapshot (#150)
### 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
2019-04-14 10:41:03 +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
Ferran Negre 8984abbf74 feat: being able to fire custom events that do not need to start with "on" (#147)
### 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
```
2019-04-09 15:37:15 +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
Kacper Wiszczuk ccad8044ea fix: check for undefined/null children (#136)
### 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
2019-03-19 19:47:26 +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
greenkeeper[bot] abd1f82898 chore: update @callstack/eslint-config to the latest version 🚀 (#134)
## The devDependency [@callstack/eslint-config](https://github.com/callstack/eslint-config-callstack) was updated from `3.0.2` to `4.0.0`.
This version is **not covered** by your **current version range**.

If you don’t accept this pull request, your project will work just like it did before. However, you might be missing out on a bunch of new features, fixes and/or performance improvements from the dependency update.

---

[Find out more about this release](https://github.com/callstack/eslint-config-callstack).

<details>
  <summary>FAQ and help</summary>

  There is a collection of [frequently asked questions](https://greenkeeper.io/faq.html). If those don’t help, you can always [ask the humans behind Greenkeeper](https://github.com/greenkeeperio/greenkeeper/issues/new).
</details>

---


Your [Greenkeeper](https://greenkeeper.io) bot 🌴
2019-03-16 09:11:32 +01:00
greenkeeper[bot] ce3bf28f30 chore: update react-native to the latest version 🚀 (#130)
* chore(package): update react-native to version 0.59.0

* chore(package): update lockfile yarn.lock

* update snapshots
2019-03-12 21:06:20 +01:00
Kacper Wiszczuk 11489b0e5e feat: wrap render with act() for better React Hooks support (#122) 2019-02-28 21:53:26 +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 3f6b257a39 chore: update react-native to version 0.57.8 (#92)
* chore(package): update react-native to version 0.57.8

* chore(package): update lockfile yarn.lock

* remove smoke test as no longer necessary
2018-12-13 22:14:23 +01:00
Michał Pierzchała bf2271dc01 fix: add errors for queryBy* helpers when more instances found (#79) 2018-11-29 10:24:22 +01:00