-
Notifications
You must be signed in to change notification settings - Fork 711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document better the details of aync methods #1012
Comments
Thanks for the detailed explanation. Could you clarify how understanding |
Hi @eps1lon:
To clarify what I mean by "flaky results" - the assertion above would fail sometimes and pass sometimes with no change to the code under test. The failure would be along the lines of the element not found. The log showed an element with content like this
The reason I opened this ticket is because I failed to get an understanding of I'd personally like a better understanding of those options, but I think they should also be provided in the documentation per this issue. |
I understand what flaky means. The question is what specific error(s) you see. That's really important here. A vague "sometimes it errors, sometimes it doesn't" will not help us identify the issue.
Yeah I agree that we assume too much knowledge here. Interval is slightly more described but we should be explicit what they do: We should document this more clearly with concrete examples. |
Thanks! So, ultimately
|
@eps1lon here is the full error:
|
import { Reducer, useEffect, useState, useReducer } from 'react';
import { DataFetchStateType, DataFetchActionType } from './types';
import reducer from './reducer';
export default function useDataFetch<DataType>(
fetchData: (...args: any[]) => Promise<DataType>,
...args: any[]
) {
const [nonce, setNonce] = useState(Date.now());
const [state, dispatch] = useReducer<
Reducer<DataFetchStateType<DataType>, DataFetchActionType<DataType>>
>(reducer, {
data: null,
error: null,
loading: true,
});
useEffect(() => {
let cancel = false;
const callDispatches = async () => {
dispatch({ type: 'get' });
try {
const data = await fetchData(...args);
if (!cancel) {
dispatch({ type: 'success', payload: { data } });
}
} catch (error) {
dispatch({ type: 'error', payload: { error: error as Error } });
}
};
callDispatches();
return () => {
cancel = true;
};
}, [nonce, ...args]);
const refetch = () => {
setNonce(Date.now());
};
return { ...state, refetch };
} |
So, I guess my inclination to increase Perhaps I could open an PR. |
Is your feature request related to a problem? Please describe.
In the example seen at the bottom of this issue, I get flaky results. The assertion passes sometimes and fails sometimes. This comes from a lack of understanding by me of how async methods work. I've Googled the heck out of it and read the docs linked below a bunch of times. I also looked through the source code, but I found it to be difficult to understand from someone who hasn't worked in this project.
Describe the solution you'd like
Ultimately, I think there are a couple of
waitFor
options that should be documented in more detail. I'd like the below questions to be answered.interval
option?timeout
option?I think this should be covered in detail here: https://testing-library.com/docs/dom-testing-library/api-async/
Describe alternatives you've considered A clear and concise description of
any alternative solutions or features you've considered.
NA
Additional context Add any other context or screenshots about the feature
request here.
Example code that has flaky results. I don't think the details of
useDataFetch
is important here, but let me know if I can answer any questions about it.The text was updated successfully, but these errors were encountered: