Comments (7)
Sorry for the delay, the PR is up
from react-native-testing-library.
Fire Event API is very simple and works by finding a matching event handler (here: onScroll) and invoking it with the supplied parameters. The fact that it did work in RN 0.72 would suggest that RN itself (or some mock provided by RN) would provide an onScroll event handler on host ScrollView rendered by composite FlatList, which in turn triggered some FlatList logic.
That's exactly what's been happening. VirtualizedList
was updating its content length inside onScroll
handler, but is no longer doing that since 0.73.
Fire Event API is not intended for RN env simulation, for that purpose, we have created the User Event API. Take a look at the scrollTo function, which should provide much better simulation by emitting multiple scroll-related events trying to mimic RN runtime behavior.
Thanks! I'll look into that more.
If you have knowledge and interest in supporting this feature in FlatList, I would encourage you to submit a PR for that. From my side, I offer help in reviewing the code and explaining RNTL intricacies if necessary.
It's possible that scrollTo
already handles that - the docs mention that it should work with FlashList
. I'll get back to this issue after some testing.
from react-native-testing-library.
Here's how we could implement this:
- user would optionally pass
contentSize
andlayoutMeasurement
values toscrollTo
call:
await userEvent.scrollTo(flatlist, {
y: 480,
contentSize: { height: 480, width: 240 },
layoutMeasurement: { height: 480, width: 240 },
});
- User Event would pass relevant values to proper individual events.
Both values seem to be stable for the duration of user interaction, so we just forward them. If User Event lacks certain event in the sequence, the we could as them.
@j-piasecki Would you be able to submit a PR for that?
from react-native-testing-library.
@j-piasecki Hmmm, I'm quite surprised to learn that fireEvent.scroll
did update anything in any RN version 🧐
Fire Event API is very simple and works by finding a matching event handler (here: onScroll
) and invoking it with the supplied parameters. The fact that it did work in RN 0.72 would suggest that RN itself (or some mock provided by RN) would provide an onScroll
event handler on host ScrollView
rendered by composite FlatList
, which in turn triggered some FlatList
logic.
Fire Event API is not intended for RN env simulation, for that purpose, we have created the User Event API. Take a look at the scrollTo
function, which should provide much better simulation by emitting multiple scroll-related events trying to mimic RN runtime behavior. Be aware that the current implementation of it is quite basic and has been based only on plain ScrollView
interactions. However, it should emit both onScroll
as well as onContentSizeChange
. If you have knowledge and interest in supporting this feature in FlatList
, I would encourage you to submit a PR for that. From my side, I offer help in reviewing the code and explaining RNTL intricacies if necessary.
from react-native-testing-library.
I've looked into this more, and it seems like scrollTo
doesn't handle that case 😞. I think the reason is twofold:
- When
scrollTo
builds scroll events, it passes zeros to all properties exceptcontentOffset
- main offenders here arecontentSize
andlayoutMeasurement
: - Because of the change mentioned in the issue description,
VirtualizedList
no longer handlescontentSize
inside itsonScroll
handler, meaning that itsonContentSizeChange
handler also would need to be invoked. Normally, this is done byScrollView
inside itsonLayout
callback, however theScrollView
is mocked and doesn't handleonLayout
at all.
At this point, I'm not sure whether it should be handled by the library or by the users on a case-by-case basis, since it's necessary only for VirtualizedLists and the documentation clearly states that it focuses on the host ScrollView
component.
from react-native-testing-library.
@j-piasecki we could extend scrollTo
API to allow passing contentSize
& layoutMeasurement
. If not passed they would default to zero.
from react-native-testing-library.
we could extend
scrollTo
API to allow passingcontentSize
&layoutMeasurement
. If not passed they would default to zero.
That would be great! This change alone should make it work with VirtualizedLists
for RN 0.72 and below, however for 0.73 triggering onContentSizeChange
is also required. Do you think it should be included in the scrollTo
API or should that be a user's responsibility?
from react-native-testing-library.
Related Issues (20)
- Unexpected element not found when adding accessibilityElementsHidden or importantForAccessibility HOT 3
- Incorrect automatic cleanup order HOT 2
- Why are accessibilty elements only text, textInput, and switch? HOT 13
- Getting "ReferenceError: jest is not defined" when on userEvent touch events HOT 9
- I am having non deterministic error after migrate to v12.4.0 HOT 13
- RN 0.74 breaking testing library HOT 10
- RFC: impact of `detectHostComponentNames` HOT 5
- waitForElementToBeRemoved doesn't work as expected with `get` type queries HOT 2
- Unexpected behavior of userEvent.press with timers HOT 1
- How to test userEvent.press() in combination with precise timers advancing? HOT 5
- Vitest support HOT 4
- `persist` method does not exist on event passed to onKeyPress HOT 3
- RFC: React 19 support HOT 6
- React 18 support HOT 7
- unstable_validateStringsRenderedWithinText immediate setState in useEffect HOT 3
- toHaveTextContent matching rules are not aligned with jest-dom HOT 2
- Configuration option for customizing error output
- act is deprecated HOT 3
- RFC: RNTL Cookbook HOT 4
- Unexpected token 'export' error when running Jest tests HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-testing-library.