-
-
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
Add .debug() method to ReactWrapper #158
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# `.debug() => String` | ||
|
||
Returns an HTML-like string of the wrapper for debugging purposes. Useful to print out to the | ||
console when tests are not passing when you expect them to. | ||
|
||
|
||
#### Returns | ||
|
||
`String`: The resulting string. | ||
|
||
|
||
|
||
#### Examples | ||
|
||
Say we have the following components: | ||
```jsx | ||
class Foo extends React.Component { | ||
render() { | ||
return ( | ||
<div className="foo"> | ||
<span>Foo</span> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
class Bar extends React.Component { | ||
render() { | ||
return ( | ||
<div className="bar"> | ||
<span>Non-Foo</span> | ||
<Foo baz="bax" /> | ||
</div> | ||
); | ||
} | ||
} | ||
``` | ||
|
||
In this case, running: | ||
```jsx | ||
console.log(mount(<Bar id="2" />).debug()); | ||
``` | ||
|
||
Would output the following to the console: | ||
```jsx | ||
<Bar id="2"> | ||
<div className="bar"> | ||
<span> | ||
Non-Foo | ||
</span> | ||
<Foo baz="bax"> | ||
<div className="foo"> | ||
<span> | ||
Foo | ||
</span> | ||
</div> | ||
</Foo> | ||
</div> | ||
</Bar> | ||
``` | ||
|
||
Likewise, running: | ||
|
||
```jsx | ||
console.log(mount(<Bar id="2" />).find(Foo).debug(); | ||
``` | ||
Would output the following to the console: | ||
```jsx | ||
<Foo baz="bax"> | ||
<div className="foo"> | ||
<span> | ||
Foo | ||
</span> | ||
</div> | ||
</Foo> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,8 @@ import { | |
indent, | ||
debugNode, | ||
} from '../Debug'; | ||
import { itIf } from './_helpers'; | ||
import { mount } from '../'; | ||
import { describeWithDOM, itIf } from './_helpers'; | ||
import { REACT013 } from '../version'; | ||
|
||
describe('debug', () => { | ||
|
@@ -188,4 +189,133 @@ describe('debug', () => { | |
|
||
}); | ||
|
||
describeWithDOM('debugInst(inst)', () => { | ||
it('renders basic debug of mounted components', () => { | ||
class Foo extends React.Component { | ||
render() { | ||
return ( | ||
<div className="foo"> | ||
<span>Foo</span> | ||
</div> | ||
); | ||
} | ||
} | ||
expect(mount(<Foo id="2" />).debug()).to.eql( | ||
`<Foo id="2"> | ||
<div className="foo"> | ||
<span> | ||
Foo | ||
</span> | ||
</div> | ||
</Foo>`); | ||
}); | ||
|
||
it('renders debug of compositional components', () => { | ||
class Foo extends React.Component { | ||
render() { | ||
return ( | ||
<div className="foo"> | ||
<span>Foo</span> | ||
</div> | ||
); | ||
} | ||
} | ||
class Bar extends React.Component { | ||
render() { | ||
return ( | ||
<div className="bar"> | ||
<span>Non-Foo</span> | ||
<Foo baz="bax" /> | ||
</div> | ||
); | ||
} | ||
} | ||
expect(mount(<Bar id="2" />).debug()).to.eql( | ||
`<Bar id="2"> | ||
<div className="bar"> | ||
<span> | ||
Non-Foo | ||
</span> | ||
<Foo baz="bax"> | ||
<div className="foo"> | ||
<span> | ||
Foo | ||
</span> | ||
</div> | ||
</Foo> | ||
</div> | ||
</Bar>`); | ||
}); | ||
|
||
it('renders a subtree of a mounted tree', () => { | ||
class Foo extends React.Component { | ||
render() { | ||
return ( | ||
<div className="foo"> | ||
<span>Foo</span> | ||
</div> | ||
); | ||
} | ||
} | ||
class Bar extends React.Component { | ||
render() { | ||
return ( | ||
<div className="bar"> | ||
<span>Non-Foo</span> | ||
<Foo baz="bax" /> | ||
</div> | ||
); | ||
} | ||
} | ||
expect(mount(<Bar id="2" />).find(Foo).debug()).to.eql( | ||
`<Foo baz="bax"> | ||
<div className="foo"> | ||
<span> | ||
Foo | ||
</span> | ||
</div> | ||
</Foo>`); | ||
}); | ||
|
||
it('renders passed children properly', () => { | ||
class Foo extends React.Component { | ||
render() { | ||
return ( | ||
<div className="foo"> | ||
<span>From Foo</span> | ||
{this.props.children} | ||
</div> | ||
); | ||
} | ||
} | ||
class Bar extends React.Component { | ||
render() { | ||
return ( | ||
<div className="bar"> | ||
<Foo baz="bax"> | ||
<span>From Bar</span> | ||
</Foo> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
expect(mount(<Bar id="2" />).debug()).to.eql( | ||
`<Bar id="2"> | ||
<div className="bar"> | ||
<Foo baz="bax"> | ||
<div className="foo"> | ||
<span> | ||
From Foo | ||
</span> | ||
<span> | ||
From Bar | ||
</span> | ||
</div> | ||
</Foo> | ||
</div> | ||
</Bar>`); | ||
|
||
}); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to see an example where a component is rendering There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point. I'll add that. |
||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
just want to confirm - these two lines will not do anything special for
true
, or for Symbols.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.
hmm.... not that I'm aware of.
I don't actually know what calling this on
<div>{true}</div>
would do, but it should do whatever react itself does...No idea how or why or what symbols would be doing getting called in this function....?
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.
just checked and
<div>{true}</div>
gets rendered as<div />
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.
In that case, wouldn't we want
if (inst === true) return ''
? or am i misunderstanding something.what about
<div>{Symbol('foo')}</div>
?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.
@ljharb
<div>{Symbol('foo')}</div>
also renderes an empty div. I think this function isn't being used exactly how you imagine it. Though i'm not sure I event 100% understand it... lol