fix(animations): getAnimationStyle causes exceptions in older browser… · angular/angular@cb1d77a

File tree

2 files changed

lines changed

  • packages/animations/browser

    • test/render/css_keyframes

2 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -140,8 +140,8 @@ function setAnimationStyle(element: any, name: string, value: string, index?: nu

140140

element.style[prop] = value;

141141

}

142142
143-

function getAnimationStyle(element: any, name: string) {

144-

return element.style[ANIMATION_PROP + name];

143+

export function getAnimationStyle(element: any, name: string) {

144+

return element.style[ANIMATION_PROP + name] || '';

145145

}

146146
147147

function countChars(value: string, char: string): number {

Original file line numberDiff line numberDiff line change

@@ -5,9 +5,8 @@

55

* Use of this source code is governed by an MIT-style license that can be

66

* found in the LICENSE file at https://angular.io/license

77

*/

8-

import {ElementAnimationStyleHandler} from '../../../src/render/css_keyframes/element_animation_style_handler';

8+

import {ElementAnimationStyleHandler, getAnimationStyle} from '../../../src/render/css_keyframes/element_animation_style_handler';

99

import {computeStyle} from '../../../src/util';

10-
1110

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

1211
1312

const EMPTY_FN = () => {};

@@ -227,5 +226,23 @@ const EMPTY_FN = () => {};

227226

element.dispatchEvent(event);

228227

expect(done).toBeTruthy();

229228

});

229+
230+

// Issue: https://github.com/angular/angular/issues/24094

231+

it('should not break getAnimationStyle in old browsers', () => {

232+

// Old browsers like Chrome Android 34 returns null if element.style

233+

// is not found, modern browsers returns empty string.

234+

const fakeElement = {

235+

style: {

236+

'animationstyle1': 'value',

237+

'animationstyle2': null,

238+

'animationstyle3': '',

239+

'animation': null

240+

}

241+

};

242+

expect(getAnimationStyle(fakeElement, 'style1')).toBe('value');

243+

expect(getAnimationStyle(fakeElement, 'style2')).toBe('');

244+

expect(getAnimationStyle(fakeElement, 'style3')).toBe('');

245+

expect(getAnimationStyle(fakeElement, '')).toBe('');

246+

});

230247

});

231248

}