-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[enhancement] #960 allow debug() to exclude props #961
Conversation
src/Debug.js
Outdated
let beforeProps = ''; | ||
if (!options.ignoreProps) { | ||
props = propsString(node); | ||
beforeProps = props ? ' ' : ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think i'd prefer to change line 72 to const props = options.ignoreProps ? '' : propsString(node);
and then none of the consts need to change to lets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok sure, I will change this to keep these using const.
src/Debug.js
Outdated
export function debugNodes(nodes) { | ||
return nodes.map(node => debugNode(node)).join('\n\n\n'); | ||
export function debugNodes(nodes, options) { | ||
return nodes.map(node => debugNode(node, undefined, options)).join('\n\n\n'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be options = {}
, since it's not a required argument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I defaulted it to empty object in debugNode(), but it makes the code more consistent to default it to empty object here too. Will do.
src/ShallowWrapper.js
Outdated
* @returns {String} | ||
*/ | ||
debug() { | ||
return debugNodes(this.getNodes()); | ||
debug(options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is optional, it should be defaulted (= {}
), so it doesn't contribute to the function's length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do. What do you mean by contributing to the function's length?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function (options) {}.length
is 1
, function (options = {}) {}.length
is 0
- a function's "length" property tells you how many required arguments it has.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes total sense! Thanks for explaining.
Feedback addressed. |
src/Debug.js
Outdated
const nodeClose = childrenStrs.length ? `</${type}>` : '/>'; | ||
|
||
const props = options.ignoreProps ? '' : propsString(node); | ||
const beforeProps = (options.ignoreProps || !props) ? '' : ' '; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the ignoreProps
option is set, then props
will be the empty string, which is falsy - i think you can just revert this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Cleaned this up. Let me know if I should squash or of it's fine to have this as an additional commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either's OK, but it's always better to rebase down to atomic commits :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM, but I'm concerned that now the shallow debug
API will deviate from that of mount
.
Could we enhance ReactWrapper
's "debug" output to support the same options?
Sure, that seems reasonable. I'll be out a week, but when I return I could do that either as part of this PR or a separate one. For the CI failure, I see:
Doesn't seem related to this change. Is there a way I can try kicking off another build? Edit: I see all 3 builds from this branch have failed. Do you know what the issue is here? |
I think it's related to npm v5 issues. I'll rebase your branch on top of my fixes and that should do it. |
b9d2571
to
cbae676
Compare
cbae676
to
f6b360d
Compare
@ljharb Added support for ReactWrapper. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks great!
I'm wondering if in addition to true
, we might want this option to also support an array of prop names to ignore - that way you could ignore className
but nothing else, for example. That can be a different PR, tho :-)
@finnigantime once tests are passing, i'll add other collabs as reviewers so we can get this in. It looks like they're failing because jsdom fails pre-iojs, and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, but could you update the docs for debug?
@nfcampos Thanks for pointing that out. Done! |
7799ed0
to
18b94f3
Compare
Implements #960. Adds options object to debug(). Uses options.ignoreProps to opt-in to ignoring props from the debug() string output. This change is backwards-compatible so existing usages of debug() are unaffected.