Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit dfbc0f6

Browse files
crisbetoThomasBurleson
authored andcommitted
fix(colors): failing unit tests against Edge (#9876)
IE and Edge convert RGB colors to RGBA automatically, which was being handled by the `colors` unit tests via browser sniffing in IE. The browser sniffing doesn't work in Edge, which was causing the tests to fail. This hasn't been noticed until now since we've only been running the tests against IE 11. These changes switch to using feature detection to check whether the browser converts to RGBA.
1 parent 757d649 commit dfbc0f6

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/components/colors/colors.spec.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ describe('md-colors', function () {
33
var $mdColorPalette, $mdTheming;
44
var supplant, scope;
55
var compiledElements = [];
6+
var usesRGBA;
67

78
beforeEach(module('material.components.colors', function ($mdThemingProvider) {
89
$mdThemingProvider.theme('myTheme')
@@ -17,6 +18,7 @@ describe('md-colors', function () {
1718
$mdTheming = $injector.get('$mdTheming');
1819
supplant = $injector.get('$mdUtil').supplant;
1920
scope = $rootScope.$new();
21+
checkColorMode();
2022
}));
2123

2224
afterEach(function() {
@@ -27,14 +29,8 @@ describe('md-colors', function () {
2729
compiledElements = [];
2830
});
2931

30-
// documentMode is an only-IE property, which confirms that the specs are currently running inside
31-
// of an Internet Explorer.
32-
var isIE = !!window.document.documentMode;
33-
3432
function buildColor(red, green, blue, opacity) {
35-
// Once the current test browser is IE11, we always have to build a RGBA string, because
36-
// IE11 automatically transforms all RGB colors into RGBA.
37-
if (angular.isDefined(opacity) || isIE) {
33+
if (angular.isDefined(opacity) || usesRGBA) {
3834
return supplant('rgba({0}, {1}, {2}, {3})', [red, green, blue, opacity || 1]);
3935
} else {
4036
return supplant('rgb({0}, {1}, {2})', [red, green, blue]);
@@ -48,6 +44,15 @@ describe('md-colors', function () {
4844
return element;
4945
}
5046

47+
// Checks whether the current browser uses RGB or RGBA colors. This is
48+
// necessary, because IE and Edge automatically convert RGB colors to RGBA.
49+
function checkColorMode() {
50+
if (angular.isUndefined(usesRGBA)) {
51+
var testerElement = compile('<div md-colors="{background: \'red\'}" >');
52+
usesRGBA = testerElement[0].style.background.indexOf('rgba') === 0;
53+
}
54+
}
55+
5156
describe('directive', function () {
5257

5358
function createElement(scope, options) {

0 commit comments

Comments
 (0)