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

[Docs] Update docs around SFC instances in React 16 #1243

Merged
merged 1 commit into from
Dec 23, 2017

Conversation

mykhailo-riabokon
Copy link
Contributor

Related to #1232

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

Thanks! So far just a few comments.

@@ -2,20 +2,62 @@

Gets the instance of the component being rendered as the root node passed into `shallow()`.

NOTE: can only be called on a wrapper instance that is also the root instance.
NOTE: can only be called on a wrapper instance that is also the root instance. With React `16.x.x`, `instance()` returns `null` for stateless React component. See example.
Copy link
Member

Choose a reason for hiding this comment

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

s/stateless React component/stateless functional components, s/example./example:


#### Returns (React 16.x.x)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need the .x.x anywhere; 16.x should be sufficient (same throughout)


- `ReactComponent`: The Statefull React component instance.
Copy link
Member

Choose a reason for hiding this comment

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

s/statefull/stateful/g

@ljharb ljharb added the docs label Oct 9, 2017
@mykhailo-riabokon
Copy link
Contributor Author

@ljharb PR was updated. Please let me know in case of mismatches.


expect(instance).not.toBe(null); // This will fail, because instance is null
Copy link
Member

Choose a reason for hiding this comment

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

this seems to be jest matcher syntax; we use chai's expect. could you update it to be expect(instance).not.to.equal(null) instead? (same throughout)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will change.

const wrapper = shallow(<Stateful />);
const instance = wrapper.instance();

expect(instance).not.toBe(null); // This will pass
Copy link
Member

Choose a reason for hiding this comment

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

let's preserve the original assertion here too: expect(inst).to.be.instanceOf(MyComponent);

Copy link
Contributor Author

@mykhailo-riabokon mykhailo-riabokon Oct 10, 2017

Choose a reason for hiding this comment

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

From an original example it's not clear (as for me) what is <MyComponent />. I mean, is it stateful or stateless. And whole purpose of this update is to show this specific case.

Copy link
Member

Choose a reason for hiding this comment

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

It's fine to show "null or not null"; I'm asking not to delete the "instance of MyComponent" checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I did not catch it.

@mykhailo-riabokon
Copy link
Contributor Author

@ljharb PR was updated.


expect(instance).not.to.equal(null); // This will pass
Copy link
Member

Choose a reason for hiding this comment

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

Please add here expect(instance).to.be.instanceOf(Stateful); as well

const wrapper = shallow(<Stateless />);
const instance = wrapper.instance();

expect(instance).not.to.equal(null); // This will pass
Copy link
Member

Choose a reason for hiding this comment

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

Please add here expect(instance).to.be.instanceOf(Stateless); as well

const wrapper = shallow(<Stateful />);
const instance = wrapper.instance();

expect(instance).not.to.equal(null); // This will pass
Copy link
Member

Choose a reason for hiding this comment

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

Please add here expect(instance).to.be.instanceOf(Stateful); as well


expect(instance).not.to.equal(null); // This will fail, because instance is null
Copy link
Member

Choose a reason for hiding this comment

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

Please add here expect(instance).not.to.be.instanceOf(Stateless); as well

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

Seems good!

@Tetheta
Copy link

Tetheta commented Dec 22, 2017

Is this something we can merge master into and get approved? Was quite helpful for me and was annoying to have to dig through PRs to find it.

@ljharb ljharb changed the title Update docs for ShallowWrapper .instance() method [Docs] Update docs around SFC instances in React 16 Dec 23, 2017
@ljharb ljharb merged commit 5b5439a into enzymejs:master Dec 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants