Skip to content

Commit

Permalink
fix(checkbox): Use correct animation end event type in adapter (#220)
Browse files Browse the repository at this point in the history
Fixes issue where wrong event type was being used within
`getCorrectEventName` in `register`/`deregisterAnimationEndHandler`
adapter methods in vanilla component. Discovered while working on #205.
  • Loading branch information
traviskaufman authored Jan 30, 2017
1 parent fd93702 commit fd04c83
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/mdc-checkbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ export class MDCCheckbox extends MDCComponent {
addClass: (className) => this.root_.classList.add(className),
removeClass: (className) => this.root_.classList.remove(className),
registerAnimationEndHandler:
(handler) => this.root_.addEventListener(getCorrectEventName(window, 'animation'), handler),
(handler) => this.root_.addEventListener(getCorrectEventName(window, 'animationend'), handler),
deregisterAnimationEndHandler:
(handler) => this.root_.removeEventListener(getCorrectEventName(window, 'animation'), handler),
(handler) => this.root_.removeEventListener(getCorrectEventName(window, 'animationend'), handler),
registerChangeHandler: (handler) => this.nativeCb_.addEventListener('change', handler),
deregisterChangeHandler: (handler) => this.nativeCb_.removeEventListener('change', handler),
getNativeControl: () => this.nativeCb_,
Expand Down
17 changes: 4 additions & 13 deletions test/unit/mdc-checkbox/mdc-checkbox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@ function getFixture() {
`;
}

const windowObj = td.object({
document: {
createElement: (str) => ({
style: {
animation: 'none',
},
}),
},
});

function setupTest() {
const root = getFixture();
const component = new MDCCheckbox(root);
Expand Down Expand Up @@ -136,7 +126,7 @@ test('adapter#registerAnimationEndHandler adds an animation end event listener o
const {root, component} = setupTest();
const handler = td.func('animationEndHandler');
component.getDefaultFoundation().adapter_.registerAnimationEndHandler(handler);
domEvents.emit(root, getCorrectEventName(windowObj, 'animation'));
domEvents.emit(root, getCorrectEventName(window, 'animationend'));

t.doesNotThrow(() => td.verify(handler(td.matchers.anything())));
t.end();
Expand All @@ -145,10 +135,11 @@ test('adapter#registerAnimationEndHandler adds an animation end event listener o
test('adapter#deregisterAnimationEndHandler removes an animation end event listener on the root el', (t) => {
const {root, component} = setupTest();
const handler = td.func('animationEndHandler');
root.addEventListener(strings.ANIM_END_EVENT_NAME, handler);
const animEndEvtName = getCorrectEventName(window, 'animationend');
root.addEventListener(animEndEvtName, handler);

component.getDefaultFoundation().adapter_.deregisterAnimationEndHandler(handler);
domEvents.emit(root, strings.ANIM_END_EVENT_NAME);
domEvents.emit(root, animEndEvtName);

t.doesNotThrow(() => td.verify(handler(td.matchers.anything()), {times: 0}));
t.end();
Expand Down

0 comments on commit fd04c83

Please sign in to comment.