@@ -70,6 +70,54 @@ describe('IterableMapper', () => {
7070 jest . clearAllMocks ( ) ;
7171 } ) ;
7272
73+ describe ( 'constructor' , ( ) => {
74+ const validInput = [ 1 , 2 , 3 ] ;
75+ const validMapper = async ( x : number ) => {
76+ await sleep ( 1 ) ;
77+ return x * 2 ;
78+ } ;
79+
80+ test ( 'should throw TypeError if mapper is not a function' , ( ) => {
81+ expect ( ( ) => {
82+ new IterableMapper ( validInput , null as any ) ;
83+ } ) . toThrow ( TypeError ) ;
84+ } ) ;
85+
86+ test ( 'should throw TypeError if concurrency is not a valid integer or Infinity' , ( ) => {
87+ expect ( ( ) => {
88+ new IterableMapper ( validInput , validMapper , { concurrency : 0 } ) ;
89+ } ) . toThrow ( TypeError ) ;
90+
91+ expect ( ( ) => {
92+ new IterableMapper ( validInput , validMapper , { concurrency : - 1 } ) ;
93+ } ) . toThrow ( TypeError ) ;
94+
95+ expect ( ( ) => {
96+ new IterableMapper ( validInput , validMapper , { concurrency : 1.5 } ) ;
97+ } ) . toThrow ( TypeError ) ;
98+ } ) ;
99+
100+ test ( 'should throw TypeError if maxUnread is not a valid integer or Infinity' , ( ) => {
101+ expect ( ( ) => {
102+ new IterableMapper ( validInput , validMapper , { maxUnread : 0 } ) ;
103+ } ) . toThrow ( TypeError ) ;
104+
105+ expect ( ( ) => {
106+ new IterableMapper ( validInput , validMapper , { maxUnread : - 1 } ) ;
107+ } ) . toThrow ( TypeError ) ;
108+
109+ expect ( ( ) => {
110+ new IterableMapper ( validInput , validMapper , { maxUnread : 1.5 } ) ;
111+ } ) . toThrow ( TypeError ) ;
112+ } ) ;
113+
114+ test ( 'should throw TypeError if maxUnread is less than concurrency' , ( ) => {
115+ expect ( ( ) => {
116+ new IterableMapper ( validInput , validMapper , { concurrency : 5 , maxUnread : 4 } ) ;
117+ } ) . toThrow ( TypeError ) ;
118+ } ) ;
119+ } ) ;
120+
73121 describe ( 'simple tests' , ( ) => {
74122 it ( 'simple mapper works - sync mapper' , async ( ) => {
75123 const max = 100 ;
0 commit comments