Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lelandrichardson
Copy link
Collaborator

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.

@@ -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);
Copy link
Member

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');
Copy link
Member

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');
Copy link
Member

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');
Copy link
Member

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);
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

@ljharb ljharb force-pushed the master branch 3 times, most recently from 40cc703 to 0a17404 Compare April 12, 2019 23:05
@ljharb ljharb force-pushed the master branch 4 times, most recently from 2227326 to 0d5ead7 Compare December 21, 2020 07:46
@ljharb ljharb force-pushed the master branch 3 times, most recently from 43eb75e to 39e6b1f Compare November 3, 2022 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants