-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add debugging helper? #31
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
Comments
Thanks for your issue and we are glad you are liking this library. I'm wondering do we really need to add these items into this library. Because to me both Coming back to your debug, again its a matter of preferences for the developers. Because I personally attach a debugger, when something is failing, well other developers might do the same way or like you had suggested. Again I'm thinking on whether to add May be when the library throws error like can't find element (when you call @kentcdodds Any thoughts? |
I agree with @antoaravinth. I do like his idea here:
We'd have to be careful though. The element to be printed could be VERY large. Perhaps we could do something like: if (htmlContent.length < config.maxLengthToLog) {
console.log(htmlContent)
} else {
console.log(`The html content has the length of ${htmlContent.length} which is larger than the default maxLengthToLog of ${config.maxLengthToLog}. Change the default in the config`)
} Of course the messaging would be improved there and you could import the config file in your |
@kentcdodds I was thinking in the same boat :) Yes we can add these things, wondering whether we need to add this helper in |
We can't do it for the I realize this still doesn't quite satisfy what you are trying to accomplish @BarthesSimpson and I'm sorry for that, but I do think your proposed methods are outside the scope of this project. However! I do have a solution. I demonstrate it in the client-side config of my testing workshop. I recommend everyone have a file like this file which re-exports the utils I use from react-testing-library as well as some custom utilities that I like to have in my app. Because I have So you could put such utilities in a file like that and it wouldn't make any difference that it's not included by default :) |
@kentcdodds Yeah your right about |
Thanks for the quick and thorough replies. @kentcdodds I do something similar to what you describe with a helper file in your modulePaths (but with more helpers, and using an alias because the helpers are used by multiple teams). Are there helpers you are interested in adding to the core lib? If so, we are interested in contributing, and if not we may just release a separate package. |
Why don't you make a separate package and if it makes sense later we can discuss including it in this library. Thanks! |
I was thinking about this, having worked with rather complex (and sometimes tangled..) react components, and was trying to figure out what would be the most useful in real life.
Printing dom structure would definitely helpful, but when we debug with tools like cypress we don't look at html structure, we look at the page as the user would - right? This printout is not very readable, it's not immediately obvious what you are looking at.
This is better but since we are skipping a lot of visual helps.. it's hard to understand what's going on. Where are the buttons, how are the elements really laid out on the page. etc..
I'd strongly vote for the option number 3. We could do more here. Obviously I'm highlighting empty space (not very problematic but could be avoided). We could highlight alts/labels, to be able to understand the elements that dont have texts on them... Possibly remove classes and styles to clean up the print out? What are you guys thinking? It would be nice to have full highlighting here, but as far as I can see no one done it, it would be quite a bit of work, and I think the most important part is still the contrast between text and markup, for comparison: Keep in mind that with different background it's easy to get the text unreadable. But the simple invert for the things you want to stand out will always work nicely ( I think ) |
@lgandecki Option 3 looks, cool. Yeah that will definitely help the user to quickly see through their page, but writing the highlighting thing would be big work I suppose (not sure whether you had already implemented the same). I was actually looking to implement the idea by printing the dom, using jest-matcher-utils, which has few methods like |
All of the things mentioned above are working. Besides the last screenshot, which, I agree - would be.a lot of work, and, worse than that - I don't think there is a way to detect the background, so it'd be very easy to make this unreadable for users. (that's why my proposition is just simple invert) I'm not familiar with jest printing dom - but if it already does nice DOM formatting with colors then just ignore my comment. :) |
@lgandecki Sure. We can see what @kentcdodds has to say on our thoughts, before we could come to a conclusion.. |
I'm looking at And I don't see anything related to html there. As for printing out colored JavaScript it actually uses this - https://www.npmjs.com/package/babel-code-frame which says:
I gave it a try and it produced this: Which is a bit inconsistent - Sometimes the actual text is yellow (same as html tags) sometimes it's the default color text. edit: babel-code-frame is actually using internally this one - https://github.com/babel/babel/tree/master/packages/babel-highlight and it's super simple |
Hmmm... Yeah, that formatting and highlighting is a little bit off. I'd love the HTML to be formatted the same way that jest formats the snapshots which I think is more legible (and totally possible with pretty-format + the built-in DOM plugins). From there we'd just need to have a good highlighting solution. I'm definitely interested in using something like that for this. Would be very cool! |
…ng-library#31) - Changes queries to default to exact string matching - Can opt-in to fuzzy matches by passing { exact: true } as the last arg - Queries that search inner text collapse whitespace (queryByText, queryByLabelText) BREAKING CHANGE: Strings are considered to be an exact match now. You can opt-into fuzzy matching, but it's recommended to use a regex instead.
We are using a UI library, which unfortunately makes the HTML a bit too verbose to read even with pretty printed HTML. I was curious if it would be possible to somehow "serve" the HTML snippet when calling debug, or at least save it to a .html file? |
I don't think we'd implement something like that in core, but you could definitely write a helper module that does that! |
Closes testing-library#306 Closes testing-library#301 Closes testing-library#235 Closes testing-library#181 Closes testing-library#172 Closes testing-library#31
…ary#308) Closes testing-library#306 Closes testing-library#301 Closes testing-library#235 Closes testing-library#181 Closes testing-library#172 Closes testing-library#31
I know you're trying to keep this awesome library lightweight. In general, I advocate avoiding using Enzyme's .debug() method, but there are times where it's invaluable in hunting down a mistake in a test. I'm currently using a few helpers to supplement your library, like this:
Usage:
Are you open to including helpers like this in the core library?
The text was updated successfully, but these errors were encountered: