Skip to content

Commit

Permalink
[enzyme-adapter-utils] [New] Add event name mapping for animation events
Browse files Browse the repository at this point in the history
  • Loading branch information
robbiemccorkell authored and ljharb committed Mar 12, 2018
1 parent e0bcdf7 commit e2302ce
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/enzyme-adapter-utils/src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import createRenderWrapper from './createRenderWrapper';

export { createMountWrapper, createRenderWrapper };

export function mapNativeEventNames(event) {
export function mapNativeEventNames(event, {
animation = false, // should be true for React 15+
} = {}) {
const nativeToReactEventMap = {
compositionend: 'compositionEnd',
compositionstart: 'compositionStart',
Expand Down Expand Up @@ -42,6 +44,11 @@ export function mapNativeEventNames(event) {
mouseenter: 'mouseEnter',
mouseleave: 'mouseLeave',
transitionend: 'transitionEnd',
...(animation && {
animationstart: 'animationStart',
animationiteration: 'animationIteration',
animationend: 'animationEnd',
}),
};

return nativeToReactEventMap[event] || event;
Expand Down
12 changes: 12 additions & 0 deletions packages/enzyme-test-suite/test/Utils-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,18 @@ describe('Utils', () => {
expect(result).to.equal('dragEnter');
});
});

describe('conditionally supported events', () => {
it('ignores unsupported events', () => {
const result = mapNativeEventNames('animationiteration');
expect(result).to.equal('animationiteration');
});

it('transforms events when supported', () => {
const result = mapNativeEventNames('animationiteration', { animation: true });
expect(result).to.equal('animationIteration');
});
});
});

describe('displayNameOfNode', () => {
Expand Down

0 comments on commit e2302ce

Please sign in to comment.