Skip to content

Commit

Permalink
Fix shallowwrapper not calling events with lowercase names
Browse files Browse the repository at this point in the history
  • Loading branch information
benstokoe committed Jan 24, 2016
1 parent ef401c7 commit d203865
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ export function nodeEqual(a, b) {
// 'click' => 'onClick'
// 'mouseEnter' => 'onMouseEnter'
export function propFromEvent(event) {
return `on${event[0].toUpperCase()}${event.substring(1)}`;
const nativeEvent = mapNativeEventNames(event);
return `on${nativeEvent[0].toUpperCase()}${nativeEvent.substring(1)}`;
}

export function withSetStateAllowed(fn) {
Expand Down
36 changes: 36 additions & 0 deletions src/__tests__/ShallowWrapper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,42 @@ describe('shallow', () => {
expect(spy.args[0][1]).to.equal(b);
});

describe('Normalizing JS event names', () => {
it('should convert lowercase events to React camelcase', () => {
const spy = sinon.spy();
class Foo extends React.Component {
render() {
return (
<a onDoubleClick={spy}>foo</a>
);
}
}

const wrapper = shallow(<Foo />);

wrapper.simulate('doubleclick');
expect(spy.calledOnce).to.equal(true);
});

describeIf(!REACT013, 'normalizing mouseenter', () => {
it('should convert lowercase events to React camelcase', () => {
const spy = sinon.spy();
class Foo extends React.Component {
render() {
return (
<a onMouseEnter={spy}>foo</a>
);
}
}

const wrapper = shallow(<Foo />);

wrapper.simulate('mouseenter');
expect(spy.calledOnce).to.equal(true);
});
});
});

});

describe('.setState(newState)', () => {
Expand Down

0 comments on commit d203865

Please sign in to comment.