Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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] || '';
AndrewKushnir marked this conversation as resolved.
Show resolved Hide resolved
}

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,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('');
});
});
}