-
Notifications
You must be signed in to change notification settings - Fork 273
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
Debug util that would only print displayed text #1135
Comments
I agree with the idea of filtering output. For instance, filtering out I do think we need customisable output. Because if you look at the preferred query discussion we're having (#1133), role is going to become a priority, so it'd need to be in the output. But if you don't care about it, it could be useful to skip it. I also think we should allow |
@pierrezimmermannbam I think that your use case is closely related to Our current API for function debugImpl(message?: string) {} react-native-testing-library/src/render.tsx Line 146 in fa21fc5
Which accepts a In comparison DTL const debug = (
element?: Array<Element | HTMLDocument> | Element | HTMLDocument,
maxLength?: number,
options?: OptionsReceived,
): void => And RTL return from debug: (el = baseElement, maxLength, options) =>
Array.isArray(el)
? // eslint-disable-next-line no-console
el.forEach(e => console.log(prettyDOM(e, maxLength, options)))
: // eslint-disable-next-line no-console,
console.log(prettyDOM(el, maxLength, options)), Quick summary:
So I think that for this we should explore accepting our own
We could also include |
I love the suggested API by @mdjastrzebski. I feel And I think it'd be nice to also expose that as global configuration through an API akin to RTL's configure. And with of course a priority if passed as an option to |
I've submitted #1141 for adding |
I really like the filterProp function, and I also agree with @AugustinLF that the filterProps looks more like a map for nodes. Regarding filterProp, I think I'd like this api better though :
I feel like there aren't many use cases where you'd need to access the node and it also requires some knowledge on ReactTestRendererJSON type so I expect most users to use mostly propName and propValue. This would allow to declare functions that take only propName and propValue as params Also, currently debug accepts an optional string param and I think we want to be able to add options without giving a string message, so it will either be a breaking change or we could go for the following api (for some time at least) const debug = (options: string | DebugOptions) => {}
type DebugOptions = {
message?: string,
filterProp,
...
} |
@mdjastrzebski @AugustinLF I opened a draft pr with a first implem for the filterProps option, I'd appreciate if you could have a look and tell me what you think about it. I have some doubts regarding the implementation, namely I haven't understand why we use ReactComponent plugin in the format function as it seems to me it's never used. Also if this gets merged additional documentation on the website should be written first |
Implemented by #1160 |
Describe the Feature
When debugging tests on large components, i.e. pages, snapshots can be very long and may not be convenient for debugging purposes. Very often I'm mostly interested in seing what text / testID is displayed on the screen and don't really care about the design so I think that a function that would log only the displayed text and maybe also the testIDs could come in pretty handy.
Possible Implementations
We'd have a function to transform the json representation into a string with just text and maybe also testIDs displayed. I implemented such a function on my current project and it looks like this :
Then the api would need to be modified to add this functionality. I'm thinking of two ways to do this :
Second option would allow more customization in the future and we may want to combine several options (for instance text and testID are visible or just text or just testID) but it also makes the api more complex and more difficult to use. Also people may not notice that this feature exists. Alternatively both approach could be combined to have an accessible and easy way of printing just text and also the ability to custom output according to one's needs.
Related Issues
No related issues as far as I know
@mdjastrzebski @AugustinLF what are your thoughts on this ?
The text was updated successfully, but these errors were encountered: