Skip to content

Commit

Permalink
[Docs] shallow/mount: fix examples, and make them consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
cadence09 authored and ljharb committed Sep 20, 2020
1 parent a3705cf commit bdb618e
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 19 deletions.
6 changes: 5 additions & 1 deletion docs/api/ReactWrapper/equals.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ like the one passed in.


```jsx
const wrapper = mount(<MyComponent />);
function MyComponent() {
return <div className="foo bar" />;
}

const wrapper = mount(<MyComponent />).childAt(0);
expect(wrapper.equals(<div className="foo bar" />)).to.equal(true);
```

Expand Down
1 change: 0 additions & 1 deletion docs/api/ReactWrapper/every.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,4 @@ expect(wrapper.find('.foo').every('.bar')).to.equal(false);
#### Related Methods

- [`.someWhere(predicate) => Boolean`](someWhere.md)
- [`.every(selector) => Boolean`](every.md)
- [`.everyWhere(predicate) => Boolean`](everyWhere.md)
2 changes: 1 addition & 1 deletion docs/api/ReactWrapper/everyWhere.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ expect(wrapper.find('.foo').everyWhere((n) => n.hasClass('bar'))).to.equal(false

- [`.some(selector) => Boolean`](some.md)
- [`.every(selector) => Boolean`](every.md)
- [`.everyWhere(predicate) => Boolean`](everyWhere.md)

2 changes: 1 addition & 1 deletion docs/api/ReactWrapper/first.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ expect(wrapper.find(Foo).first().props().foo).to.equal('bar');

#### Related Methods

- [`.at(index) => ReactWrapper`](at.md) - retrieve any wrapper node
- [`.at(index) => ReactWrapper`](at.md) - retrieve a wrapper node at given index
- [`.last() => ReactWrapper`](last.md)
8 changes: 4 additions & 4 deletions docs/api/ReactWrapper/instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ class Stateful extends React.Component {

#### React 16.x
```jsx
test('shallow wrapper instance should be null', () => {
test('mount 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', () => {
test('mount wrapper instance should not be null', () => {
const wrapper = mount(<Stateful />);
const instance = wrapper.instance();

Expand All @@ -44,14 +44,14 @@ test('shallow wrapper instance should not be null', () => {

#### React 15.x
```jsx
test('shallow wrapper instance should not be null', () => {
test('mount 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', () => {
test('mount wrapper instance should not be null', () => {
const wrapper = mount(<Stateful />);
const instance = wrapper.instance();

Expand Down
2 changes: 1 addition & 1 deletion docs/api/ReactWrapper/matchesElement.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MyComponent extends React.Component {
}
}

const wrapper = mount(<MyComponent />);
const wrapper = mount(<MyComponent />).childAt(0);
expect(wrapper.matchesElement(<button>Hello</button>)).to.equal(true);
expect(wrapper.matchesElement(<button className="foo bar">Hello</button>)).to.equal(true);
```
Expand Down
3 changes: 2 additions & 1 deletion docs/api/ReactWrapper/render.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ function Bar() {

```jsx
const wrapper = mount(<Bar />);
expect(wrapper.find(Foo).render().find('.in-foo')).to.have.lengthOf(1);
expect(wrapper.find('.in-foo')).to.have.lengthOf(1);
expect(wrapper.render().find('.in-foo')).to.have.lengthOf(1);
```
8 changes: 4 additions & 4 deletions docs/api/ReactWrapper/simulate.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ const wrapper = mount((
/>
));

expect(wrapper.find('input').at(0).prop('value')).toEqual(10);
expect(wrapper.find('input').at(1).prop('value')).toEqual(20);
expect(wrapper.find('input').at(0).props().value).to.equal(10);
expect(wrapper.find('input').at(1).props().value).to.equal(20);
wrapper.find('input').at(0).simulate('change', { target: { name: 'width', value: 50 } });
wrapper.find('input').at(1).simulate('change', { target: { name: 'height', value: 70 } });
expect(testState.width).toEqual(50);
expect(testState.height).toEqual(70);
expect(testState.width).to.equal(50);
expect(testState.height).to.equal(70);
```

#### Common Gotchas
Expand Down
5 changes: 3 additions & 2 deletions docs/api/ReactWrapper/type.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ If it's `null`, it will be `null`. It must be a single-node wrapper.
function Foo() {
return <div />;
}
const wrapper = mount(<Foo />);
const wrapper = mount(<Foo />).childAt(0);
expect(wrapper.type()).to.equal('div');
```

Expand All @@ -38,7 +38,8 @@ function Foo() {
return <Bar />;
}
const wrapper = mount(<Foo />);
expect(wrapper.type()).to.equal(Bar);
expect(wrapper.type()).to.equal(Foo);
expect(wrapper.childAt(0).type()).to.equal(Bar);
```

```jsx
Expand Down
4 changes: 4 additions & 0 deletions docs/api/ShallowWrapper/equals.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ like the one passed in.


```jsx
function MyComponent() {
return <div className="foo bar" />;
}

const wrapper = shallow(<MyComponent />);
expect(wrapper.equals(<div className="foo bar" />)).to.equal(true);
```
Expand Down
1 change: 0 additions & 1 deletion docs/api/ShallowWrapper/every.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,4 @@ expect(wrapper.find('.foo').every('.bar')).to.equal(false);
#### Related Methods

- [`.someWhere(predicate) => Boolean`](someWhere.md)
- [`.every(selector) => Boolean`](every.md)
- [`.everyWhere(predicate) => Boolean`](everyWhere.md)
2 changes: 1 addition & 1 deletion docs/api/ShallowWrapper/first.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ expect(wrapper.find(Foo).first().props().foo).to.equal('bar');

#### Related Methods

- [`.at(index) => ShallowWrapper`](at.md) - retrieve any wrapper node
- [`.at(index) => ShallowWrapper`](at.md) - retrieve a wrapper node at given index
- [`.last() => ShallowWrapper`](last.md)
2 changes: 1 addition & 1 deletion docs/api/ShallowWrapper/render.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ function Bar() {
```jsx
const wrapper = shallow(<Bar />);
expect(wrapper.find('.in-foo')).to.have.lengthOf(0);
expect(wrapper.find(Foo).render().find('.in-foo')).to.have.lengthOf(1);
expect(wrapper.render().find('.in-foo')).to.have.lengthOf(1);
```

0 comments on commit bdb618e

Please sign in to comment.