113 Commits

Author SHA1 Message Date
Michał Pierzchała 8d69c40d84 fix: bring back RenderAPI type (#1000)
* fix: bring back RenderAPI type

* add test

* fix
2022-06-24 12:36:19 +02:00
Maciej Jastrzebski 64ff2d27c2 refactor: re-organise regular (non A11y) queries by predicate (#965)
* refactor: move queries files to queries folder

* refactor: fix import order

* refactor: extract bindByTextQueries

* refactor: extract bindByTestId, bindByDisplayValue

* refactor: extract bindByPlaceholderText

* refactor: remove findByAPI

* refactor: re-organied flow types

* refactor: migrate getByAPI & queryByAPI

* refactor: simplify query file names

* refactor: reduce external visibility

* refactor: reduce unnecessary exports

* refactor: self code review

* refactor: self code review

* refactor: move query tests to `src/queries/__tests__`

* refactor: remove removed functions errors
2022-05-04 12:08:03 +02:00
Pierre Zimmermann 564e99056a feat: add renderHook function (#923)
* feat: add renderHook function

* docs: add documentation on renderhook

* chore(renderHook): add flow typing

* docs: improve readability and consistency

Co-authored-by: pierrezimmermann <pierrez@nam.tech>
Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
2022-04-26 14:53:59 +02:00
Augustin Le Fèvre 1360b73295 feat(breaking): migrate Flow to TS; remove some deprecated functions and aliases (#881)
* Port types to TS

* Fix CI commands

* Fix typo in yml file

* Address PR comments

* Remove aliased accessibility queries

* Add flow types

* Update build to support TS

* Clean up removed aliased queries

* Move @babel/plugin-transform-flow-strip-types to test config

* Address PR comments

* Delete flow tests

* Retrigger pipeline

* Update src/helpers/timers.ts

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
2022-03-25 16:54:30 +01:00
Pierre Zimmermann 49dbb66f8e feat: allow getByText and queryByText to find text nested in fragments (#934)
Co-authored-by: pierrezimmermann <pierrez@nam.tech>
2022-03-25 10:24:05 +01:00
Jared Beach 6667cc2e20 feat: adds onTimeout option to waitFor (#885) 2022-01-10 13:09:24 +01:00
Augustin Le Fèvre 31ef0b92ed feat(breaking): add text match options a.k.a string precision API (#554)
* Add TextMatch options to getByAPI

* Add TextMatch options to queryByAPI

* Add TextMatch options to findByAPI

* Add tests covering new TextMatch options

* Add documentation and examples for TextMatch options

* Implement text match normalization customization

* Implement tests for normalization options

* Add text normalization docs

* Refactor typings

* Add export for getDefaultNormalizer function

* Remove undocumented config for normalizer function

* Update website/docs/Queries.md

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

* BREAKING: make findBy* queries arguments order compatible with RTL

* Fix tests for findBy queries after changing their API

* Fix matching nested Text components with queryOptions exact set to true

* Remove recursion matching for *byText APIs

* Reuse getAllByText in getByText

* Add Textmatch options to *byTestId

* fix: types for getDefaultNormalizer

* refactor: remove makeNormalizer and use getDefaultNormalizer() instead

* refactor: change params position and description for matches

* refactor: move & remove duplicated tests after merge

* Make waitForOptions param change non breaking change

* chore: cleanup and type fixups

* tests: update snapshots

* chore: use default arg value for normalizer

* Restore mock after use

* fix: wrong snapshot update with outdated deps

Co-authored-by: Rafał Zakrzewski <zakrzewski.rafal@gmail.com>
Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
Co-authored-by: Maciej Jastrzebski <mdjastrzebski@gmail.com>
Co-authored-by: Damian Sznajder <damsznajder@gmail.com>
2021-11-23 16:30:25 +01:00
Augustin Le Fèvre 3735b0e41f Forward extra data to press event (#828) 2021-10-15 21:02:34 +02:00
Nick McCurdy b6ec6b0198 chore: rename default branch to main (#784) 2021-10-15 20:39:35 +02:00
Michał Pierzchała 7726a6d074 chore: upgrade Jest and RN to latest (#837)
* chore: upgrade Jest and RN to latest

* chore: update test timeout
2021-10-15 20:36:26 +02:00
Andrei Alecu 1cbf51644e test: add failing test for #776 (#778) 2021-07-06 16:13:23 +02:00
MattAgn ffda1de9f9 Extract tests by queries (#666)
* test: extract byText related tests

* test: extract byDisplayValue related tests

* test: extract byPlaceholderTest related tests

* test: delete unused code in byText test

* test: delete unused code in byTest tests

* test: delete unused code in byDisplayValue tests

* test: delete unused code in byPlaceholderText tests

* test: replace class components with function components
2021-05-17 16:30:57 +02:00
Michael McDermott e0236a5117 fix: wrap unmount in act (#706) 2021-03-19 18:02:13 +01:00
Pontus Lundin 8510d6d47c feat(breaking): do not throw because event handler was not found (#691)
* do not throw when event handler was not found

* remove unnecessary hasDescendandHandler

Co-authored-by: Pontus Lundin <pontus.lundin@klarna.com>
Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
2021-03-02 15:02:31 +01:00
Mike Duminy 2ccec3c3a3 fix(breaking): use real timers internally to fix awaiting with fake timers (#568)
* capture global timers, use them in waitFor, tests+

* use real timers in flushMicroTasks

* test to show changes with modern timer mocks

* use enum-like object for timer modes

* fix tests

* remove default timer mode, add flow types
export other timer helpers, adjust tests and docs

* base waitFor on RTL implementation

* [jest] Capture and restore global promise

* [waitFor] Simulate intervals when using fake timers

* [tests] Fix waitForElementToBeRemoved

* cleanups; use more specific global

* rename globals to match others

Co-authored-by: Michael James Duminy <michael-james.duminy@klarna.com>
Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
2021-03-02 13:49:30 +01:00
Michał 2aa6609523 feat: support pointerEvents (#655)
* test: add pointerEvents test

* feat: add pointerEvents handling

* test: add test for nested views

* feat: add pointerEvents box-none handling

* test: handle auto pointerEvents

* Update src/__tests__/fireEvent.test.js

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
2021-02-05 15:05:46 +01:00
MattAgn 34fc03a8c9 Finish refactoring queries using new query builder makeQueries (#654)
* refactor: extract method filterNodeByType

* feat: use makeQueries for byText

* feat: use makeQueries for byPlaceholderText

* feat: use makeQueries for byDisplayValue

* refactor: renamed method in queryAllByTestId

* refactor: rename method makeQuery to makeA11yQuery

the renaming is done to avoid any confusion with makeQueries which should be the new way to add new queries

* test: add test for errors for byTestId

* sort exports

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
2021-02-05 14:53:45 +01:00
MattAgn f2a7cca3f2 fix: getByDisplayValue not checking TextInput's defaultValue (#656)
* fix: make getByDisplayValue check the default value of text inputs

* fix: make getByDisplayValue only use defaultValue if value is undefined

if the value of TextInput is an empty string, then the TextInput will not use the defaultValue and display the empty string. Our tests now do the same
2021-01-25 14:12:48 +01:00
MattAgn d71a7d8afc chore: restructure ByTestId queries code by predicate type (#608)
* refactor: add makeQueries functions

* refactor: use new query builders on byTestId

* rebase and rearrange to a bit

* add fixme

* refactor: make single function makeQueries

* doc: add TODO to do before end of pr

* fix: fix flow issue

* parametrize Queries

* chore: delete duplicated test

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
2021-01-13 12:28:47 +01:00
Michał 91200ef448 Updated React imports (#629)
Co-authored-by: Michał Parkitny <michal.parkitny@callstack.com>
2020-12-10 10:44:02 +01:00
Michał d6265d9dcb chore: bump React Native to 0.64 RC (#626)
* chore: bump React Native to 0.64 RC

* Snapshot update

* Bumped node version to 12 on CI

* Removed removed supress_comment syntax from config

* codemod types-first

* Prettied files after codemod

* Added flow types to API returns

* don't return null from fireEvent handlers

* return ReactTestInstance instead of any

* fix render returning any

* less anys

* less anys

* simplify call type

* simplify

* add Flow to missing files, type debug better

Co-authored-by: Michał Parkitny <michal.parkitny@callstack.com>
Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
2020-12-09 17:49:39 +01:00
Matthieu Gicquel b0244d9451 fix: display stack trace and code frame for findBy error (#581)
Inspired by https://github.com/testing-library/dom-testing-library/blob/master/src/wait-for.js
2020-12-09 12:05:03 +01:00
Abílio Costa 808aa3150e Add onMoveShouldSetResponder to element enabled checking (#577)
* fix: add onMoveShouldSetResponder to element enabled checking

* Update src/fireEvent.js

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

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
Co-authored-by: Maciej Jastrzebski <mdjastrzebski@gmail.com>
2020-11-03 19:14:40 +01:00
Michał Klekowski 78fb456b8a feat: export container from render (#567)
* feat: export root test instance from render

* test: add tests for root test instance returned from render function

* docs: add description about root test instance returned from render function

* feat: change root export to container and wrap component in View if no wrapper defined

* docs: update description about container test instance returned from render function

* test: update tests for root test instance returned from render function

* test: clean up comments in tests

* feat: add react-native as peerDependency, clean up lint ignore for lines that was importing react-native

* revert adding default wrapper

* rework tests

* reword docs

* add testID checks

* add comments

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
2020-10-21 12:26:01 +02:00
Alan Kenyon 696b28b9c3 fix: non-responder wrapping host elements ignore disabled prop (#572)
* test showing the issue

* don't pass non-responder host elements as decsecendants

* linter fixs

* attempting to improve readability

* refactor: re-structure code for clarity & redability

Co-authored-by: Maciej Jastrzebski <mdjastrzebski@gmail.com>
2020-10-21 11:50:09 +02:00
Simon Reggiani 484c9f7790 feat: add the value expected in getBy error messages (#550)
* add the value expected in getBy error messages (e.g. "No instances found with text 'bla'")

* updated a11y test

* rename fullNoInstanceError to getNoInstancesFoundMessage

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

* addressing PR comments

* fixed lint error

Co-authored-by: Maciej Jastrzebski <mdjastrzebski@gmail.com>
2020-10-12 18:01:42 +02:00
Panagiotis Plytas f68f3120ec feat: support 'editable' prop on TextInput (#517)
* test: Add tests for non-editable TextInput

* feat: use editable prop to check for event handling
2020-09-07 22:42:22 +02:00
Alvaro Catalina d55ea0b0b4 feat: RegExp support for *ByTestId queries (#535)
* getAllByTestId supports a regex matcher

* update typings

* docs: update

* refactor types

* refactor. remove unnecessary try/catch

* refactor test assertions
2020-09-07 22:39:16 +02:00
AugustinLF 9f6ca56ac0 fix: Return closest Text matching a query (#489)
* fix: Return closest Text matching a query

* Add test for another edge case

* Fix whitespaces

* adjust comment

* Update src/helpers/getByAPI.js

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

* update test

* use queryBy

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
Co-authored-by: Maciej Jastrzebski <mdjastrzebski@gmail.com>
2020-08-16 21:26:29 +02:00
Maciej Jastrzebski 00a50a89b3 fix: fire event should not throw for disabled handler (#470)
* updated tests

* feat: implement behavior chage

* code review changes

* refactor: more strict test conditions
2020-07-31 10:34:00 +02:00
Maciej Jastrzebski 5adf148de5 feat: prevent events on disabled elements (#460)
* feat: add tests

* feat: prevent event handling on disabled element

* refactor: code cleanup

* feat: use props.onStartShouldSetResponder to check for event handling

* refactor: code review changes

* feat: updated docs

* feat: added test for fake 'disabled' prop
2020-07-30 16:13:15 +02:00
Maciej Jastrzebski 37f0c42a1f fix: update package name in docs (#462)
* fix: package reference in docs

* fix: more references to package name

* Update README.md

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

* Update website/docs/GettingStarted.md

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

* Update website/docs/API.md

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
2020-07-30 16:13:15 +02:00
Maciej Jastrzebski 3f88cacbc6 feat: add getQueriesForElement alias to within (#461)
* feat: getQueriesForElement alias implementation & test

* feat: added typescript types and tests

* feat: updated docs
2020-07-30 16:13:15 +02:00
Michał Pierzchała 6d63a4f29e feat(breaking): rename ByPlaceholder to ByPlaceholderText (#455) 2020-07-30 16:13:15 +02:00
Ryan Wessel 61359c70e6 feat: introduce ByLabelText, ByRole and ByHintText a11y aliases (#445)
* feat: Add alias accessibilityLabel queries to assist in migrating from @testing-library/react-native

* feat: Add alias accessibilityHint queries to assist in migrating from @testing-library/react-native

* feat: Add alias accessibilityRole queries to assist in migrating from @testing-library/react-native

* feat: Add to A11yAPI types to include the newly-aliased queries for label, hint, and role

* test: Add tests for newly-aliased label, hint, and role a11y queries

* test: Add newly-alised a11y queries to the index typings test file

* docs: Add query aliases for testing library migrators to Queries documentation

* test: Consolidate aliased query tests into shared tests. FIXME's where there are errors

* test: Update a11yAPI tests to assert referential equality for query aliases

* refactor: apply Prettier formatting to a11yAPI test file

* fix: address typos in CONTRIBUTING.md

* test: Separate referential quality assertion tests for query aliases into their own tests

Co-authored-by: Ryan Wessel <rwessel@dataminr.com>
2020-07-21 15:46:06 +02:00
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