Skip to content

Commit

Permalink
Merge 8a2e505 into f347d47
Browse files Browse the repository at this point in the history
  • Loading branch information
paulvollmer committed Oct 6, 2019
2 parents f347d47 + 8a2e505 commit 13064bf
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ matrix:
- node_js: "6"
env: REACT=0.13
env:
- REACT=16.10
- REACT=16.9
- REACT=16.8
- REACT=16.7
Expand Down
34 changes: 33 additions & 1 deletion docs/api/ReactWrapper/simulate.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Simulate events on the root node in the wrapper. It must be a single-node wrappe
`ReactWrapper`: Returns itself.


#### Example
#### Example `class component`

```jsx
class Foo extends React.Component {
Expand Down Expand Up @@ -45,7 +45,39 @@ wrapper.find('a').simulate('click');
expect(wrapper.find('.clicks-1').length).to.equal(1);
```

#### Example `functional component`

```jsx
const Foo = ({ width, height, onChange }) => (
<div>
<input name="width" value={width} onChange={onChange} />
<input name="height" value={height} onChange={onChange} />
</div>
);
Foo.propTypes = {
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
onChange: PropTypes.func.isRequired,
};

const testState = { width: 10, height: 20 };
const wrapper = mount((
<Foo
width={testState.width}
height={testState.height}
onChange={(e) => {
testState[e.target.name] = e.target.value;
}}
/>
));

expect(wrapper.find('input').at(0).prop('value')).toEqual(10);
expect(wrapper.find('input').at(1).prop('value')).toEqual(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);
```

#### Common Gotchas

Expand Down
35 changes: 34 additions & 1 deletion docs/api/ShallowWrapper/simulate.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Simulate events on the root node in the wrapper. It must be a single-node wrappe
`ShallowWrapper`: Returns itself.


#### Example
#### Example `class component`

```jsx
class Foo extends React.Component {
Expand Down Expand Up @@ -45,6 +45,39 @@ wrapper.find('a').simulate('click');
expect(wrapper.find('.clicks-1').length).to.equal(1);
```

#### Example `functional component`

```jsx
const Foo = ({ width, height, onChange }) => (
<div>
<input name="width" value={width} onChange={onChange} />
<input name="height" value={height} onChange={onChange} />
</div>
);
Foo.propTypes = {
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
onChange: PropTypes.func.isRequired,
};

const testState = { width: 10, height: 20 };
const wrapper = shallow((
<Foo
width={testState.width}
height={testState.height}
onChange={(e) => {
testState[e.target.name] = e.target.value;
}}
/>
));

expect(wrapper.find('input').at(0).prop('value')).toEqual(10);
expect(wrapper.find('input').at(1).prop('value')).toEqual(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);
```

#### Common Gotchas

Expand Down

0 comments on commit 13064bf

Please sign in to comment.