From 2e26399179ed4b49ab543f35fd8ee44d9c81430b Mon Sep 17 00:00:00 2001 From: Serginho Date: Thu, 4 Apr 2019 14:08:57 +0200 Subject: [PATCH] fix(animations): getAnimationStyle causes exceptions in older browsers PR #29709 getAnimationStyle causes exceptions in older browsers --- .../element_animation_style_handler.ts | 4 ++-- .../element_animation_style_handler_spec.ts | 21 +++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/animations/browser/src/render/css_keyframes/element_animation_style_handler.ts b/packages/animations/browser/src/render/css_keyframes/element_animation_style_handler.ts index 0ef602b0d810d..352c7fe247913 100644 --- a/packages/animations/browser/src/render/css_keyframes/element_animation_style_handler.ts +++ b/packages/animations/browser/src/render/css_keyframes/element_animation_style_handler.ts @@ -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 { diff --git a/packages/animations/browser/test/render/css_keyframes/element_animation_style_handler_spec.ts b/packages/animations/browser/test/render/css_keyframes/element_animation_style_handler_spec.ts index 0d2420e9fd02d..bc2258d7b61c8 100644 --- a/packages/animations/browser/test/render/css_keyframes/element_animation_style_handler_spec.ts +++ b/packages/animations/browser/test/render/css_keyframes/element_animation_style_handler_spec.ts @@ -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(''); + }); }); }