@@ -770,4 +770,44 @@ describe('Test lib.js:', function() {
770770 } ) ;
771771 } ) ;
772772
773+ describe ( 'fillUnique' , function ( ) {
774+
775+ beforeEach ( function ( ) {
776+ this . obj = { a : 'A' } ;
777+ this . array = [ 'a' , 'b' , 'c' , this . obj ] ;
778+ } ) ;
779+
780+ it ( 'should fill new items in array' , function ( ) {
781+ var out = Lib . fillUnique ( this . array , 'd' ) ;
782+
783+ expect ( this . array ) . toEqual ( [ 'a' , 'b' , 'c' , { a : 'A' } , 'd' ] ) ;
784+ expect ( this . array ) . toBe ( out ) ;
785+ } ) ;
786+
787+ it ( 'should ignore falsy items' , function ( ) {
788+ Lib . fillUnique ( this . array , false ) ;
789+ expect ( this . array ) . toEqual ( [ 'a' , 'b' , 'c' , { a : 'A' } ] ) ;
790+
791+ Lib . fillUnique ( this . array , undefined ) ;
792+ expect ( this . array ) . toEqual ( [ 'a' , 'b' , 'c' , { a : 'A' } ] ) ;
793+
794+ Lib . fillUnique ( this . array , 0 ) ;
795+ expect ( this . array ) . toEqual ( [ 'a' , 'b' , 'c' , { a : 'A' } ] ) ;
796+
797+ Lib . fillUnique ( this . array , null ) ;
798+ expect ( this . array ) . toEqual ( [ 'a' , 'b' , 'c' , { a : 'A' } ] ) ;
799+
800+ Lib . fillUnique ( this . array , '' ) ;
801+ expect ( this . array ) . toEqual ( [ 'a' , 'b' , 'c' , { a : 'A' } ] ) ;
802+ } ) ;
803+
804+ it ( 'should ignore item already in array' , function ( ) {
805+ Lib . fillUnique ( this . array , 'a' ) ;
806+ expect ( this . array ) . toEqual ( [ 'a' , 'b' , 'c' , { a : 'A' } ] ) ;
807+
808+ Lib . fillUnique ( this . array , this . obj ) ;
809+ expect ( this . array ) . toEqual ( [ 'a' , 'b' , 'c' , { a : 'A' } ] ) ;
810+ } ) ;
811+ } ) ;
812+
773813} ) ;
0 commit comments