Skip to content

Commit

Permalink
fix(animations): getAnimationStyle causes exceptions in older browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
Serginho committed Mar 1, 2020
1 parent 699ecac commit fb2f0a8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Expand Up @@ -133,8 +133,8 @@ function setAnimationStyle(element: any, name: string, value: string, index?: nu
element.style[prop] = value;
}

function getAnimationStyle(element: any, name: string) {
return element.style[ANIMATION_PROP + name];
export function getAnimationStyle(element: any, name: string) {
return element.style[ANIMATION_PROP + name] || '';
}

function countChars(value: string, char: string): number {
Expand Down
Expand Up @@ -5,9 +5,8 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {ElementAnimationStyleHandler} from '../../../src/render/css_keyframes/element_animation_style_handler';
import {ElementAnimationStyleHandler, getAnimationStyle} from '../../../src/render/css_keyframes/element_animation_style_handler';
import {computeStyle} from '../../../src/util';

import {assertStyle, createElement, makeAnimationEvent, supportsAnimationEventCreation} from './shared';

const EMPTY_FN = () => {};
Expand Down Expand Up @@ -227,5 +226,21 @@ const EMPTY_FN = () => {};
element.dispatchEvent(event);
expect(done).toBeTruthy();
});

// Issue: https://github.com/angular/angular/issues/24094
it('should not break getAnimationStyle in old browsers', () => {
// Old browsers like Chrome Android 34 returns null if element.style
// is not found, modern browsers returns empty string.
const fakeElement = {
style: {
'animation-name': 'fooAnimation',
'animation-end': null,
'animation-duration': ''
}
};
expect(getAnimationStyle(fakeElement, 'name')).toBe('fooAnimation');
expect(getAnimationStyle(fakeElement, 'duration')).toBe('');
expect(getAnimationStyle(fakeElement, 'end')).toBe('');
});
});
}

0 comments on commit fb2f0a8

Please sign in to comment.