-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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.
- Loading branch information
1 parent
7754696
commit 2932d8c
Showing
69 changed files
with
334 additions
and
327 deletions.
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
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 |
---|---|---|
@@ -1,18 +1,22 @@ | ||
# `.first() => ReactWrapper` | ||
|
||
Reduce the set of matched nodes to the first in the set. | ||
|
||
Reduce the set of matched nodes to the first in the set, just like `.at(0)`. | ||
|
||
|
||
#### Returns | ||
|
||
`ReactWrapper`: A new wrapper that wraps the first node in the set. | ||
|
||
|
||
|
||
#### Examples | ||
|
||
```jsx | ||
const wrapper = mount(<MyComponent />); | ||
expect(wrapper.find(Foo).first().props().foo).to.equal('bar'); | ||
``` | ||
|
||
|
||
#### Related Methods | ||
|
||
- [`.at(index) => ReactWrapper`](at.md) - retrieve any wrapper node | ||
- [`.last() => ReactWrapper`](last.md) |
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 |
---|---|---|
@@ -1,18 +1,25 @@ | ||
# `.hostNodes() => ReactWrapper` | ||
|
||
Returns a new wrapper with only host nodes. | ||
|
||
When using `react-dom`, host nodes are HTML elements rather than custom React components, e.g. `<div>` versus `<MyComponent>`. | ||
|
||
|
||
#### Returns | ||
|
||
`ReactWrapper`: A new wrapper that wraps the filtered nodes. | ||
|
||
|
||
|
||
#### Examples | ||
|
||
The following code takes a wrapper with two nodes, one a `<MyComponent>` React component, and the other a `<span>`, and filters out the React component. | ||
|
||
```jsx | ||
const wrapper = mount(<div><MyComponent className="foo" /><div className="foo" /></div>); | ||
expect(wrapper.find('.foo').hostNodes()).to.have.lengthOf(1); | ||
const wrapper = mount(( | ||
<div> | ||
<MyComponent className="foo" /> | ||
<span className="foo" /> | ||
</div> | ||
)); | ||
const twoNodes = wrapper.find('.foo'); | ||
expect(twoNodes.hostNodes()).to.have.lengthOf(1); | ||
``` |
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 |
---|---|---|
@@ -1,19 +1,60 @@ | ||
# `.instance() => ReactComponent` | ||
|
||
Returns the wrapper's underlying instance. | ||
Returns the single-node wrapper's node's underlying class instance; `this` in its methods. It must be a single-node wrapper. | ||
|
||
NOTE: With React `16` and above, `instance()` returns `null` for stateless functional components. | ||
|
||
|
||
#### Returns | ||
|
||
`ReactComponent|DOMComponent`: The retrieved instance. | ||
|
||
|
||
|
||
#### Example | ||
|
||
<!-- eslint react/prop-types: 0, react/prefer-stateless-function: 0 --> | ||
```jsx | ||
function Stateless() { | ||
return <div>Stateless</div>; | ||
} | ||
|
||
class Stateful extends React.Component { | ||
render() { | ||
return <div>Stateful</div>; | ||
} | ||
} | ||
``` | ||
|
||
#### React 16.x | ||
```jsx | ||
const wrapper = mount(<MyComponent />); | ||
const inst = wrapper.instance(); | ||
expect(inst).to.be.instanceOf(MyComponent); | ||
test('shallow wrapper instance should be null', () => { | ||
const wrapper = mount(<Stateless />); | ||
const instance = wrapper.instance(); | ||
|
||
expect(instance).to.equal(null); | ||
}); | ||
|
||
test('shallow wrapper instance should not be null', () => { | ||
const wrapper = mount(<Stateful />); | ||
const instance = wrapper.instance(); | ||
|
||
expect(instance).to.be.instanceOf(Stateful); | ||
}); | ||
``` | ||
|
||
#### React 15.x | ||
```jsx | ||
test('shallow wrapper instance should not be null', () => { | ||
const wrapper = mount(<Stateless />); | ||
const instance = wrapper.instance(); | ||
|
||
expect(instance).to.be.instanceOf(Stateless); | ||
}); | ||
|
||
test('shallow wrapper instance should not be null', () => { | ||
const wrapper = mount(<Stateful />); | ||
const instance = wrapper.instance(); | ||
|
||
expect(instance).to.be.instanceOf(Stateful); | ||
}); | ||
``` |
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
Oops, something went wrong.