fix(animations): getAnimationStyle causes exceptions in older browsers (#29709)

PR #29709 getAnimationStyle causes exceptions in older browsers

PR Close #29709
This commit is contained in:
Serginho 2019-04-04 14:08:57 +02:00 committed by Andrew Kushnir
parent 5fa767363d
commit 66d863febe
2 changed files with 21 additions and 4 deletions

View File

@ -140,8 +140,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 {

View File

@ -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 = () => {};
@ -227,5 +226,23 @@ 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: {
'animationstyle1': 'value',
'animationstyle2': null,
'animationstyle3': '',
'animation': null
}
};
expect(getAnimationStyle(fakeElement, 'style1')).toBe('value');
expect(getAnimationStyle(fakeElement, 'style2')).toBe('');
expect(getAnimationStyle(fakeElement, 'style3')).toBe('');
expect(getAnimationStyle(fakeElement, '')).toBe('');
});
});
}