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 ab #1947

Merged
merged 1 commit into from
Jan 21, 2019
Merged

Docs ab #1947

merged 1 commit into from
Jan 21, 2019

Conversation

allan-bonadio
Copy link
Contributor

@allan-bonadio allan-bonadio commented Dec 17, 2018

Overhaul to a lot of ReactWrapper and ShallowWrapper method files, plus others.

  • Defined 'solo' as a wrapper with one node, and used that terminology throughout. Removed the term 'current node' as applied to a wrapper, and changed each to better wording.
  • rewrote sections for functions matchesElement, containsMatchingElement, containsAllMatchingElements, containsAnyMatchingElements; each refer to containsMatchIngElement and matchesElement for matching rules. Renamed the matcher node to 'patternNode' to avoid confusion.
  • compared Shallow and React wrapper methods, corrected a few discrepancies
  • added some notes for methods in React or Shallow that are not in the other
  • added .length to both the React and Shallow directories.

Closes #1919.

 - Defined 'solo' as a wrapper with one node, and used that terminology throughout.  Removed the term 'current node' as applied to a wrapper, and changed each to better wording.
 - rewrote sections for functions matchesElement, containsMatchingElement, containsAllMatchingElements, containsAnyMatchingElements; each refer to containsMatchIngElement and matchesElement for matching rules.  Renamed the matcher node to 'patternNode' to avoid confusion.
 - compared Shallow and React wrapper methods, corrected a few discrepancies
 - added some notes for methods in React or Shallow that are not in the other
 - added .length to both the React and Shallow directories.
@allan-bonadio allan-bonadio mentioned this pull request Dec 17, 2018
10 tasks
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.

It'd be very helpful if these could be broken up into separate commits for each kind of change - as it is, this is quite a lot to review.

@@ -6,8 +6,7 @@ Enzyme
[![npm Version](https://img.shields.io/npm/v/enzyme.svg)](https://www.npmjs.com/package/enzyme) [![License](https://img.shields.io/npm/l/enzyme.svg)](https://www.npmjs.com/package/enzyme) [![Build Status](https://travis-ci.org/airbnb/enzyme.svg)](https://travis-ci.org/airbnb/enzyme) [![Coverage Status](https://coveralls.io/repos/airbnb/enzyme/badge.svg?branch=master&service=github)](https://coveralls.io/github/airbnb/enzyme?branch=master)


Enzyme is a JavaScript Testing utility for React that makes it easier to assert, manipulate,
and traverse your React Components' output.
Enzyme is a JavaScript Testing utility for React that makes it easier to test your React Components' output.
Copy link
Member

Choose a reason for hiding this comment

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

Why this change? The previous version was correct - i think it's important to mention manipulation and traversal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just because something is technically correct, doesn't mean it's informative to someone who's never used Enzyme. When I first read that, I dismissed it as technical mumbo-jumbo. I didn't want to assert, manipulate or traverse, I wanted to test my software. I had to do the tut to figure out what enzyme does. This is the elevator speech; you have to make it as simple as possible. Maybe instead of 'test' it could be 'verify' or 'analyze'. I get it that you can simulate some stuff; maybe 'analyze' can cover that, too.

Copy link
Member

Choose a reason for hiding this comment

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

I definitely like "test" over "assert" (although the two are largely synonymous), but manipulation and traversal are critical means of testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what kind of 'manipulation'? certainly you can do stuff with these wrappers, but I don't think you can actually change, say, the nesting of nodes. You can run them through some runtime simulations: simulate, state, props, etc. I can't think of a simple word for this.

I'm trying to think of someway that 'traverse' might be considered part of 'test'. I'm not trying to take the wind out of enzyme's sails, I just want a naive reader to say "That's exactly what I need!"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is now:
Enzyme is a JavaScript Testing utility for React that makes it easier to test your React Components' output.
You can also manipulate, traverse and in some ways simulate runtime given the output.

Copy link
Member

Choose a reason for hiding this comment

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

You can set props and state.

current node's ancestors in the tree, starting with itself.

Note: can only be called on a wrapper of a single node.
wrapped node's ancestors in the tree, starting with itself. The wrapper must be solo.
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 "solo" is a particularly clear term; "a single node" seems clearer to me. Can these changes be reverted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, it's referring to a wrapper, so the whole phrase is "wrapper of a single node". That's 5 words. "Single-node wrapper" is 3 words; I was trying to get it down to two words. There's a lot of methods that only work on single-node wrappers, and a lot of functions that return them. In fact, it's almost like they're a subclass of Wrapper, with their own methods like closest, instance, etc. I count 17 such methods. We don't need a subclass, just a noun. You can get away with defining a term in just a few well-traveled places, say like "must be a solo wrapper (with just 1 child)". They figure it out.

Copy link
Member

Choose a reason for hiding this comment

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

Word count isn't the thing that's going to solely determine how easy it is to digest; people can skim over phrases just as easily as words.

I don't want to invent a new noun in the quest for reducing confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about we just stick to 'single-node wrapper'?

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good to me!

# `.containsAllMatchingElements(nodes) => Boolean`
# `.containsAllMatchingElements(patternNodes) => Boolean`

Returns whether or not all of the given react elements in `patternNodes` match an element in the wrapper's render tree. Every single element of `patternNodes` must be matched one or more times. Matching follows the rules for `containsMatchingElement`.
Copy link
Member

Choose a reason for hiding this comment

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

containsMatchingElement should probably be a related method here

Copy link
Member

Choose a reason for hiding this comment

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

also, doesn't this matching really follow the rules of matchesElement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. lemme clean this up more.


Returns whether or not one of the given react elements is matching on element in the render tree.
It will determine if an element in the wrapper __looks like__ one of the expected element by checking if all props of the expected element are present on the wrappers element and equals to each other.
Returns whether or not at least one of the given react elements in `patternNodes` matches an element in the wrapper's render tree. One or more elements of `patternNodes` must be matched one or more times. Matching follows the rules for `containsMatchingElement`.
Copy link
Member

Choose a reason for hiding this comment

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

containsMatchingElement should probably be a related method here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -12,7 +12,7 @@ Returns whether or not the current node exists. Or, if a selector is passed in,

#### Returns

`Boolean`: whether or not the current node exists, or the selector had any results.
`Boolean`: whether or not any nodes are on the list, or the selector had any matches.
Copy link
Member

Choose a reason for hiding this comment

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

"on the list" isn't really a term that makes sense to me; maybe "the wrapper contains any nodes"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changing it to
...whether or not any nodes exist in the wrapper


### 2. Prop Selector
Copy link
Member

Choose a reason for hiding this comment

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

Why remove this section?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's part of regular CSS so I merged it into the CSS case. Isn't it?

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 a bit different, because you can select on prop values - which can be numbers or booleans as well as strings. CSS selectors only and exclusively operate on string values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, but the result looks almost the same. '[num=51]' will match num={51}, but not num='51'. And, '[num="51"]' will match num='51' but not num={51}. I think that should get a better description.
Meanwhile, these constructs can mix in with the rest of the CSS selector, so isn't it a part of CSS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be good to have a full accounting of the differences between enzyme selectors and css selectors. There was one phrase in there, "Further, enzyme supports combining any of those supported syntaxes together to uniquely identify a single node." I misinterpreted that to mean you can only select one node if you combine syntaxes. I rewrote the section.

@@ -79,11 +78,11 @@ const myComponents = wrapper.find(MyComponent);



### 4. A React Component’s displayName
### 3. A React Component’s displayName

enzyme allows you to find components based on a component’s `displayName`. If a component exists
in a render tree where its `displayName` is set and has its first character as a capital letter,
Copy link
Member

Choose a reason for hiding this comment

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

this isn't technically accurate; for example, things like withSomeHOC(ComponentName) can also be found in many cases (as noted below); perhaps this sentence needs updating as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand what the problem is. Isn't displayName sortof self-service?

@@ -1,6 +1,7 @@
# Static Rendering API

enzyme's `render` function is used to render react components to static HTML and analyze the
Use enzyme's `render` function to generate HTML text from your React tree,
Copy link
Member

Choose a reason for hiding this comment

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

"HTML text" is a contradiction; something is either HTML, or text. "static HTML" is the proper term here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and I thought of 'static' as meaning, 'class-based' or 'standing in one spot', neither of which made sense. how about just 'HTML'?

@@ -1,14 +1,15 @@
# `.type() => String|Function|null`
# `.type() => String | Function | null`
Copy link
Member

Choose a reason for hiding this comment

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

I believe the jsdoc-based convention here is to not have spaces around the |, even if it's less readable that way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i'll put them back

docs/api/ShallowWrapper/parent.md Show resolved Hide resolved
@ljharb ljharb added the docs label Dec 17, 2018
@allan-bonadio
Copy link
Contributor Author

allan-bonadio commented Jan 21, 2019 via email

@ljharb
Copy link
Member

ljharb commented Jan 21, 2019

I'll rebase it and take another pass :-) thanks for your patience!

@ljharb ljharb force-pushed the docs-ab branch 2 times, most recently from 63193df to 2932d8c Compare January 21, 2019 22:11
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, this was a lot of effort and it's much appreciated!

@ljharb ljharb merged commit 2932d8c into enzymejs:master Jan 21, 2019
ljharb added a commit that referenced this pull request Jan 22, 2019
@allan-bonadio
Copy link
Contributor Author

allan-bonadio commented Jan 23, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants