@@ -2,6 +2,7 @@ describe('md-colors', function () {
2
2
var $compile , $rootScope ;
3
3
var $mdColorPalette , $mdTheming ;
4
4
var supplant , scope ;
5
+ var compiledElements = [ ] ;
5
6
6
7
beforeEach ( module ( 'material.components.colors' , function ( $mdThemingProvider ) {
7
8
$mdThemingProvider . theme ( 'myTheme' )
@@ -18,6 +19,14 @@ describe('md-colors', function () {
18
19
scope = $rootScope . $new ( ) ;
19
20
} ) ) ;
20
21
22
+ afterEach ( function ( ) {
23
+ compiledElements . forEach ( function ( element ) {
24
+ element . remove ( ) ;
25
+ } ) ;
26
+
27
+ compiledElements = [ ] ;
28
+ } ) ;
29
+
21
30
// documentMode is an only-IE property, which confirms that the specs are currently running inside
22
31
// of an Internet Explorer.
23
32
var isIE = ! ! window . document . documentMode ;
@@ -32,18 +41,25 @@ describe('md-colors', function () {
32
41
}
33
42
}
34
43
44
+ // Compiles a template and keeps track of the elements so they can be cleaned up properly.
45
+ function compile ( template ) {
46
+ var element = $compile ( template ) ( scope ) ;
47
+ compiledElements . push ( element ) ;
48
+ return element ;
49
+ }
50
+
35
51
describe ( 'directive' , function ( ) {
36
52
37
53
function createElement ( scope , options ) {
38
54
var style = supplant ( "{theme}-{palette}-{hue}-{opacity}" , {
39
- attrs : options . attrs ,
40
- palette : options . palette ,
41
- theme : options . theme || 'default' ,
42
- hue : options . hue || ( options . palette === 'accent' ? 'A200' : '500' ) ,
43
- opacity : options . opacity || 1
44
- } ) ;
55
+ attrs : options . attrs ,
56
+ palette : options . palette ,
57
+ theme : options . theme || 'default' ,
58
+ hue : options . hue || ( options . palette === 'accent' ? 'A200' : '500' ) ,
59
+ opacity : options . opacity || 1
60
+ } ) ;
45
61
var markup = supplant ( '<div md-colors="{background: \'{0}\'}" {1} ></div>' , [ style , options . attrs ] ) ;
46
- var element = $ compile( markup ) ( scope ) ;
62
+ var element = compile ( markup ) ;
47
63
48
64
scope . $apply ( function ( ) {
49
65
angular . element ( document . body ) . append ( element ) ;
@@ -141,7 +157,7 @@ describe('md-colors', function () {
141
157
} ) ;
142
158
143
159
} ) ;
144
-
160
+
145
161
describe ( 'themes' , function ( ) {
146
162
/**
147
163
* <div md-colors="{background: 'primary'}">
@@ -294,7 +310,7 @@ describe('md-colors', function () {
294
310
295
311
296
312
var markup = '<div md-theme="myTheme"><div md-colors="{background: \'primary\'}" ></div></div>' ;
297
- var element = $ compile( markup ) ( scope ) ;
313
+ var element = compile ( markup ) ;
298
314
299
315
expect ( element . children ( ) [ 0 ] . style . background ) . toContain ( expectedRGB ) ;
300
316
} ) ;
@@ -313,7 +329,7 @@ describe('md-colors', function () {
313
329
314
330
scope . theme = 'myTheme' ;
315
331
var markup = '<div md-theme="{{theme}}"><div md-colors="{background: \'primary\'}" ></div></div>' ;
316
- var element = $ compile( markup ) ( scope ) ;
332
+ var element = compile ( markup ) ;
317
333
318
334
expect ( element . children ( ) [ 0 ] . style . background ) . toContain ( expectedRGB ) ;
319
335
@@ -355,9 +371,9 @@ describe('md-colors', function () {
355
371
/**
356
372
* <div md-colors="{ background: color() }" >
357
373
*/
358
- it ( 'should accept function' , inject ( function ( $compile ) {
374
+ it ( 'should accept function' , function ( ) {
359
375
var color = $mdColorPalette [ 'light-blue' ] [ '200' ] . value ;
360
- var element = $ compile( '<div md-colors="{background: color()}"></div>' ) ( scope ) ;
376
+ var element = compile ( '<div md-colors="{background: color()}"></div>' ) ;
361
377
var expectedRGBa = buildColor ( color [ 0 ] , color [ 1 ] , color [ 2 ] , 0.8 ) ;
362
378
363
379
scope . color = function ( ) {
@@ -366,13 +382,13 @@ describe('md-colors', function () {
366
382
scope . $apply ( ) ;
367
383
368
384
expect ( element [ 0 ] . style . background ) . toContain ( expectedRGBa ) ;
369
- } ) ) ;
385
+ } ) ;
370
386
371
387
/**
372
388
* <div md-colors="{ background: test ? 'red' : 'lightBlue' }" >
373
389
*/
374
- it ( 'should accept ternary value' , inject ( function ( $compile , $timeout ) {
375
- var element = $ compile( '<div md-colors="{background: \'{{test ? \'red\' : \'lightBlue\'}}\'}"></div>' ) ( scope ) ;
390
+ it ( 'should accept ternary value' , inject ( function ( $timeout ) {
391
+ var element = compile ( '<div md-colors="{background: \'{{test ? \'red\' : \'lightBlue\'}}\'}"></div>' ) ;
376
392
var color = $mdColorPalette [ 'light-blue' ] [ '500' ] . value ;
377
393
var red = $mdColorPalette [ 'red' ] [ '500' ] . value ;
378
394
var expectedRGB = buildColor ( color [ 0 ] , color [ 1 ] , color [ 2 ] ) ;
@@ -458,7 +474,7 @@ describe('md-colors', function () {
458
474
* <div md-colors="{background: '{{color}}' }" >
459
475
*/
460
476
it ( 'should delete old colors when getting an empty object' , function ( ) {
461
- var element = $ compile( '<div md-colors="{{color}}"></div>' ) ( scope ) ;
477
+ var element = compile ( '<div md-colors="{{color}}"></div>' ) ;
462
478
463
479
scope . color = '{background: \'red\'}' ;
464
480
scope . $apply ( ) ;
@@ -490,7 +506,7 @@ describe('md-colors', function () {
490
506
* <div md-colors="" >
491
507
*/
492
508
it ( 'should accept empty value and not color the element' , function ( ) {
493
- var element = $ compile( '<div md-colors=""></div>' ) ( scope ) ;
509
+ var element = compile ( '<div md-colors=""></div>' ) ;
494
510
495
511
expect ( element [ 0 ] . style . background ) . toBe ( '' ) ;
496
512
} ) ;
@@ -499,7 +515,7 @@ describe('md-colors', function () {
499
515
* <div md-colors="{}" >
500
516
*/
501
517
it ( 'should accept empty object and not color the element' , function ( ) {
502
- var element = $ compile( '<div md-colors="{}"></div>' ) ( scope ) ;
518
+ var element = compile ( '<div md-colors="{}"></div>' ) ;
503
519
504
520
expect ( element [ 0 ] . style . background ) . toBe ( '' ) ;
505
521
} ) ;
0 commit comments