Skip to content

Commit

Permalink
added test for event triggered on composite element
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuno Campos committed May 8, 2016
1 parent 882b23c commit 8855eb9
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion test/ShallowWrapper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ describe('shallow', () => {

});

it('should propagate events', () => {
it('should propagate events triggered on native elements', () => {
const innerOnClick = sinon.spy();
const outerOnClick = sinon.spy();
class Foo extends React.Component {
Expand All @@ -887,6 +887,32 @@ describe('shallow', () => {
expect(outerOnClick.calledOnce).to.equal(true);
});

it('should propagate events triggered on composite elements', () => {
class Bar extends React.Component {
render() {
return <div>bar</div>;
}
}

const innerOnClick = sinon.spy();
const outerOnClick = sinon.spy();
class Foo extends React.Component {
render() {
return (
<div onClick={outerOnClick}>
<Bar onClick={innerOnClick} />
</div>
);
}
}

const wrapper = shallow(<Foo />);

wrapper.find(Bar).simulate('click');
expect(innerOnClick.calledOnce).to.equal(true);
expect(outerOnClick.calledOnce).to.equal(true);
});

it('should respect event.stopPropagation()', () => {
const innerOnClick = sinon.spy(e => {
e.stopPropagation();
Expand Down

0 comments on commit 8855eb9

Please sign in to comment.