@@ -76,47 +76,82 @@ export function main() {
7676 . toThrowError ( `Cannot find 'type' pipe supporting object 'some object'` ) ;
7777 } ) ;
7878
79- describe ( '.append()' , ( ) => {
80- it ( 'should create a factory that appends new pipes to old' , ( ) => {
81- firstPipeFactory . spy ( "supports" ) . andReturn ( false ) ;
79+ describe ( '.create()' , ( ) => {
80+ it ( "should create a new Pipes object" , ( ) => {
81+ firstPipeFactory . spy ( "supports" ) . andReturn ( true ) ;
82+ firstPipeFactory . spy ( "create" ) . andReturn ( firstPipe ) ;
83+
84+ var pipes = Pipes . create ( { 'async' : [ firstPipeFactory ] } ) ;
85+ expect ( pipes . get ( "async" , "first" ) ) . toBe ( firstPipe ) ;
86+ } ) ;
87+
88+ it ( "should prepend passed it config in existing registry" , ( ) => {
89+ firstPipeFactory . spy ( "supports" ) . andReturn ( true ) ;
8290 secondPipeFactory . spy ( "supports" ) . andReturn ( true ) ;
8391 secondPipeFactory . spy ( "create" ) . andReturn ( secondPipe ) ;
92+
93+ var pipes1 = Pipes . create ( { 'async' : [ firstPipeFactory ] } ) ;
94+ var pipes2 = Pipes . create ( { 'async' : [ secondPipeFactory ] } , pipes1 ) ;
95+
96+ expect ( pipes2 . get ( "async" , "first" ) ) . toBe ( secondPipe ) ;
97+ } ) ;
98+
99+ it ( "should use inherited pipes when no overrides support the provided object" , ( ) => {
100+ firstPipeFactory . spy ( "supports" ) . andReturn ( true ) ;
101+ firstPipeFactory . spy ( "create" ) . andReturn ( firstPipe ) ;
102+ secondPipeFactory . spy ( "supports" ) . andReturn ( false ) ;
103+
104+ var pipes1 = Pipes . create ( { 'async' : [ firstPipeFactory ] , 'date' : [ firstPipeFactory ] } ) ;
105+ var pipes2 = Pipes . create ( { 'async' : [ secondPipeFactory ] } , pipes1 ) ;
106+
107+ expect ( pipes2 . get ( "async" , "first" ) ) . toBe ( firstPipe ) ;
108+ expect ( pipes2 . get ( "date" , "first" ) ) . toBe ( firstPipe ) ;
109+ } ) ;
110+ } ) ;
111+
112+ describe ( ".extend()" , ( ) => {
113+ it ( 'should create a factory that prepend new pipes to old' , ( ) => {
114+ firstPipeFactory . spy ( "supports" ) . andReturn ( true ) ;
115+ secondPipeFactory . spy ( "supports" ) . andReturn ( true ) ;
116+ secondPipeFactory . spy ( "create" ) . andReturn ( secondPipe ) ;
117+
84118 var originalPipes = new Pipes ( { 'async' : [ firstPipeFactory ] } ) ;
85- var binding = Pipes . append ( { 'async' :< PipeFactory [ ] > [ secondPipeFactory ] } ) ;
119+ var binding = Pipes . extend ( { 'async' :< PipeFactory [ ] > [ secondPipeFactory ] } ) ;
86120 var pipes : Pipes = binding . toFactory ( originalPipes ) ;
87121
88122 expect ( pipes . config [ 'async' ] . length ) . toBe ( 2 ) ;
89123 expect ( originalPipes . config [ 'async' ] . length ) . toBe ( 1 ) ;
90124 expect ( pipes . get ( 'async' , 'second plz' ) ) . toBe ( secondPipe ) ;
91125 } ) ;
92126
93-
94- it ( 'should append to di-inherited pipes' , ( ) => {
95- firstPipeFactory . spy ( "supports" ) . andReturn ( false ) ;
127+ it ( 'should throw if calling extend when creating root injector' , ( ) => {
96128 secondPipeFactory . spy ( "supports" ) . andReturn ( true ) ;
97129 secondPipeFactory . spy ( "create" ) . andReturn ( secondPipe ) ;
98130
131+ var injector : Injector =
132+ Injector . resolveAndCreate ( [ Pipes . extend ( { 'async' : [ secondPipeFactory ] } ) ] ) ;
133+
134+ expect ( ( ) => injector . get ( Pipes ) )
135+ . toThrowError ( / C a n n o t e x t e n d P i p e s w i t h o u t a p a r e n t i n j e c t o r / g) ;
136+ } ) ;
137+
138+ it ( 'should extend di-inherited pipes' , ( ) => {
139+ firstPipeFactory . spy ( "supports" ) . andReturn ( true ) ;
140+ firstPipeFactory . spy ( "create" ) . andReturn ( firstPipe ) ;
141+
142+ secondPipeFactory . spy ( "supports" ) . andReturn ( false ) ;
143+
99144 var originalPipes : Pipes = new Pipes ( { 'async' : [ firstPipeFactory ] } ) ;
100145 var injector : Injector = Injector . resolveAndCreate ( [ bind ( Pipes ) . toValue ( originalPipes ) ] ) ;
101146 var childInjector : Injector =
102- injector . resolveAndCreateChild ( [ Pipes . append ( { 'async' : [ secondPipeFactory ] } ) ] ) ;
147+ injector . resolveAndCreateChild ( [ Pipes . extend ( { 'async' : [ secondPipeFactory ] } ) ] ) ;
148+
103149 var parentPipes : Pipes = injector . get ( Pipes ) ;
104150 var childPipes : Pipes = childInjector . get ( Pipes ) ;
151+
105152 expect ( childPipes . config [ 'async' ] . length ) . toBe ( 2 ) ;
106153 expect ( parentPipes . config [ 'async' ] . length ) . toBe ( 1 ) ;
107- expect ( childPipes . get ( 'async' , 'second plz' ) ) . toBe ( secondPipe ) ;
108- } ) ;
109-
110-
111- it ( 'should throw if calling append when creating root injector' , ( ) => {
112- secondPipeFactory . spy ( "supports" ) . andReturn ( true ) ;
113- secondPipeFactory . spy ( "create" ) . andReturn ( secondPipe ) ;
114-
115- var injector : Injector =
116- Injector . resolveAndCreate ( [ Pipes . append ( { 'async' : [ secondPipeFactory ] } ) ] ) ;
117-
118- expect ( ( ) => injector . get ( Pipes ) )
119- . toThrowError ( / C a n n o t a p p e n d t o P i p e s w i t h o u t a p a r e n t i n j e c t o r / g) ;
154+ expect ( childPipes . get ( 'async' , 'second plz' ) ) . toBe ( firstPipe ) ;
120155 } ) ;
121156 } ) ;
122157 } ) ;
0 commit comments