-
-
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
[BREAKING] Add .rendered() and make shallow() and mount() semantics consistent #1113
base: master
Are you sure you want to change the base?
Conversation
@@ -3780,7 +3792,7 @@ describe('shallow', () => { | |||
const wrapper = shallow(<Foo />); | |||
expect(wrapper).to.have.length(1); | |||
expect(wrapper.html()).to.equal(null); | |||
expect(wrapper.type()).to.equal(null); | |||
expect(wrapper.rendered().length).to.equal(0); |
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.
Why is this not expect(wrapper.rendered()).to.eql([null])
?
@@ -2558,7 +2570,7 @@ describe('shallow', () => { | |||
|
|||
const context = { name: 'foo' }; | |||
const wrapper = shallow(<Foo />); | |||
expect(wrapper.find(Bar).shallow({ context }).text()).to.equal('foo'); | |||
expect(wrapper.find(Bar).shallow({ context }).rendered().text()).to.equal('foo'); |
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 this is the same issue as .first('div')
above, let's fix
|
||
wrapper.setProps({ x: 5 }); // Just force a re-render | ||
expect(wrapper.first('div').text()).to.equal('yolo'); |
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 shouldn't need to be changed
@@ -4178,7 +4190,7 @@ describe('shallow', () => { | |||
Foo.displayName = 'CustomWrapper'; | |||
|
|||
const wrapper = shallow(<Wrapper />); | |||
expect(wrapper.name()).to.equal('CustomWrapper'); | |||
expect(wrapper.rendered().name()).to.equal('CustomWrapper'); |
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.
add expect(wrapper.name()).to.equal('Wrapper')
@@ -4319,10 +4331,10 @@ describe('shallow', () => { | |||
|
|||
it('dives + shallow-renders when there is one component child', () => { | |||
const wrapper = shallow(<DoubleWrapsRendersDOM />); | |||
expect(wrapper.is(WrapsRendersDOM)).to.equal(true); | |||
expect(wrapper.rendered().is(WrapsRendersDOM)).to.equal(true); |
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.
add expect(wrapper.is(DoubleWrapsRendersDOM)).to.equal(true)
@@ -96,7 +96,7 @@ export function generateEmptyRenderData() { | |||
{ message: 'false', value: false, expectResponse: true }, | |||
{ message: 'null', value: null, expectResponse: true }, | |||
|
|||
// Returns false for empty, valid returns | |||
// // Returns false for empty, valid returns |
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.
?
40cc703
to
0a17404
Compare
2227326
to
0d5ead7
Compare
43eb75e
to
39e6b1f
Compare
to: @ljharb
This PR updates shallow() to have similar semantics to mount() with respect to what the wrapper that is returned by them.
The idea is that mount() and shallow() both return a wrapper that's around the Foo itself, and not what it rendered. This means that calling .type() and .instance() on the resulting wrapper will return Foo and an instance of Foo respectively.
This is essentially the alternative to #1107
This is a huge breaking change, and i'm not convinced that this is the right API. But putting up this PR for comments. Theoretically, I find it slightly more appealing than #1107, but there might be some things in this PR that are done slightly wrong. Not sure how I feel TBH.