1+ describe ( "errorDisplay" , function ( ) {
2+
3+ var $location , compileHTML ;
4+
5+ beforeEach ( module ( 'docsApp' ) ) ;
6+
7+ beforeEach ( inject ( function ( $injector ) {
8+ var $rootScope = $injector . get ( '$rootScope' ) ,
9+ $compile = $injector . get ( '$compile' ) ;
10+
11+ $location = $injector . get ( '$location' ) ;
12+
13+ compileHTML = function ( code ) {
14+ var elm = angular . element ( code ) ;
15+ $compile ( elm ) ( $rootScope ) ;
16+ $rootScope . $digest ( ) ;
17+ return elm ;
18+ } ;
19+
20+ this . addMatchers ( {
21+ toInterpolateTo : function ( expected ) {
22+ // Given a compiled DOM node with a minerr-display attribute,
23+ // assert that its interpolated string matches the expected text.
24+ return this . actual . text ( ) === expected ;
25+ }
26+ } ) ;
27+ } ) ) ;
28+
29+ it ( 'should interpolate a template with no parameters' , function ( ) {
30+ var elm ;
31+
32+ spyOn ( $location , 'search' ) . andReturn ( { } ) ;
33+ elm = compileHTML ( '<div error-display="This is a test"></div>' ) ;
34+ expect ( elm ) . toInterpolateTo ( 'This is a test' ) ;
35+ } ) ;
36+
37+ it ( 'should interpolate a template with no parameters when search parameters are present' , function ( ) {
38+ var elm ;
39+
40+ spyOn ( $location , 'search' ) . andReturn ( { p0 : 'foobaz' } ) ;
41+ elm = compileHTML ( '<div error-display="This is a test"></div>' ) ;
42+ expect ( elm ) . toInterpolateTo ( 'This is a test' ) ;
43+ } ) ;
44+
45+ it ( 'should correctly interpolate search parameters' , function ( ) {
46+ var elm ;
47+
48+ spyOn ( $location , 'search' ) . andReturn ( { p0 : '42' } ) ;
49+ elm = compileHTML ( '<div error-display="The answer is {0}"></div>' ) ;
50+ expect ( elm ) . toInterpolateTo ( 'The answer is 42' ) ;
51+ } ) ;
52+
53+ it ( 'should interpolate parameters in the specified order' , function ( ) {
54+ var elm ;
55+
56+ spyOn ( $location , 'search' ) . andReturn ( { p0 : 'second' , p1 : 'first' } ) ;
57+ elm = compileHTML ( '<div error-display="{1} {0}"></div>' ) ;
58+ expect ( elm ) . toInterpolateTo ( 'first second' ) ;
59+ } ) ;
60+
61+ it ( 'should preserve interpolation markers when fewer arguments than needed are provided' , function ( ) {
62+ var elm ;
63+
64+ spyOn ( $location , 'search' ) . andReturn ( { p0 : 'Fooooo' } ) ;
65+ elm = compileHTML ( '<div error-display="This {0} is {1} on {2}"></div>' ) ;
66+ expect ( elm ) . toInterpolateTo ( 'This Fooooo is {1} on {2}' ) ;
67+ } ) ;
68+ } ) ;
0 commit comments