@@ -599,8 +599,8 @@ describe('injector', function() {
599599 expect ( function ( ) {
600600 createInjector ( [ function ( $provide ) {
601601 $provide . factory ( 'service' , function ( service ) { } ) ;
602- return function ( service ) { }
603- } ] )
602+ return function ( service ) { } ;
603+ } ] ) ;
604604 } ) . toThrowMinErr ( '$injector' , 'cdep' , 'Circular dependency found: service' ) ;
605605 } ) ;
606606
@@ -610,37 +610,51 @@ describe('injector', function() {
610610 createInjector ( [ function ( $provide ) {
611611 $provide . factory ( 'a' , function ( b ) { } ) ;
612612 $provide . factory ( 'b' , function ( a ) { } ) ;
613- return function ( a ) { }
614- } ] )
613+ return function ( a ) { } ;
614+ } ] ) ;
615615 } ) . toThrowMinErr ( '$injector' , 'cdep' , 'Circular dependency found: b <- a' ) ;
616616 } ) ;
617+
617618 } ) ;
618619 } ) ;
619620
620621
621622 describe ( 'retrieval' , function ( ) {
622- var instance ,
623- $injector ,
624- $provide ;
623+ var instance = { name :'angular' } ;
624+ var Instance = function ( ) { this . name = 'angular' ; } ;
625625
626- beforeEach ( function ( ) {
627- $injector = createInjector ( [ [ '$provide' , function ( provide ) {
628- ( $provide = provide ) . value ( 'instance' , instance = { name :'angular' } ) ;
626+ function createInjectorWithValue ( instanceName , instance ) {
627+ return createInjector ( [ [ '$provide' , function ( provide ) {
628+ provide . value ( instanceName , instance ) ;
629+ } ] ] ) ;
630+ }
631+ function createInjectorWithFactory ( serviceName , serviceDef ) {
632+ return createInjector ( [ [ '$provide' , function ( provide ) {
633+ provide . factory ( serviceName , serviceDef ) ;
629634 } ] ] ) ;
635+ }
636+
637+
638+ it ( 'should retrieve by name' , function ( ) {
639+ var $injector = createInjectorWithValue ( 'instance' , instance ) ;
640+ var retrievedInstance = $injector . get ( 'instance' ) ;
641+ expect ( retrievedInstance ) . toBe ( instance ) ;
630642 } ) ;
631643
632644
633- it ( 'should retrieve by name and cache instance' , function ( ) {
634- expect ( instance ) . toEqual ( { name : 'angular' } ) ;
645+ it ( 'should cache instance' , function ( ) {
646+ var $injector = createInjectorWithFactory ( 'instance' , function ( ) { return new Instance ( ) ; } ) ;
647+ var instance = $injector . get ( 'instance' ) ;
635648 expect ( $injector . get ( 'instance' ) ) . toBe ( instance ) ;
636649 expect ( $injector . get ( 'instance' ) ) . toBe ( instance ) ;
637650 } ) ;
638651
639652
640653 it ( 'should call functions and infer arguments' , function ( ) {
641- expect ( $injector . invoke ( function ( instance ) { return instance ; } ) ) . toBe ( instance ) ;
654+ var $injector = createInjectorWithValue ( ' instance' , instance ) ;
642655 expect ( $injector . invoke ( function ( instance ) { return instance ; } ) ) . toBe ( instance ) ;
643656 } ) ;
657+
644658 } ) ;
645659
646660
0 commit comments