import { createMock } from 'ts-auto-mock' ; describe ( 'typescript lib' , ( ) => { it ( 'should set an empty array' , ( ) => { interface Interface { a : Array < boolean > ; } const properties = createMock < Interface > ( ) ; expect ( properties . a ) . toEqual ( [ ] ) ; } ) ; it ( 'should set the default value for a number' , ( ) => { interface Interface { a : Number ; } const properties = createMock < Interface > ( ) ; expect ( properties . a ) . toBe ( 0 ) ; } ) ; it ( 'should set the default value for a string' , ( ) => { interface Interface { a : String ; } const properties = createMock < Interface > ( ) ; expect ( properties . a ) . toBe ( '' ) ; } ) ; it ( 'should set the default value for a boolean' , ( ) => { interface Interface { a : Boolean ; } const properties = createMock < Interface > ( ) ; expect ( properties . a ) . toBe ( false ) ; } ) ; it ( 'should set the default value for empty object' , ( ) => { interface Interface { a : object ; } const properties = createMock < Interface > ( ) ; expect ( properties . a ) . toEqual ( { } ) ; } ) ; it ( 'should set the default value for an Object' , ( ) => { interface Interface { a : Object ; } const properties = createMock < Interface > ( ) ; expect ( properties . a ) . toEqual ( { } ) ; } ) ; it ( 'should set an empty function for a function' , ( ) => { interface Interface { a : Function ; } const properties = createMock < Interface > ( ) ; expect ( properties . a ( ) ) . toBeUndefined ( ) ; } ) ; it ( 'should set an empty array for a ReadOnlyArray' , ( ) => { interface Interface { a : ReadonlyArray < boolean > ; } const properties = createMock < Interface > ( ) ; expect ( properties . a ) . toEqual ( [ ] ) ; } ) ; it ( 'should create a new Date for a Date' , ( ) => { interface Interface { a : Date ; } const properties = createMock < Interface > ( ) ; expect ( properties . a ) . toBeInstanceOf ( Date ) ; } ) ; it ( 'should set a promise resolved for a promise' , async ( ) => { interface Interface { a ( ) : Promise < string > ; } const properties = createMock < Interface > ( ) ; const interfaceCast = properties as unknown as Interface ; const result = await interfaceCast . a ( ) ; expect ( result ) . toBe ( '' ) ; } ) ; it ( 'should set a promise resolved for a promise with array' , async ( ) => { interface Interface { a ( ) : Promise < string [ ] > ; } const properties = createMock < Interface > ( ) ; const interfaceCast = properties as unknown as Interface ; const result = await interfaceCast . a ( ) ; expect ( result ) . toEqual ( [ ] ) ; } ) ; it ( 'should set a promise resolved for a promise with more generics' , async ( ) => { interface WithGenerics < T > { generic : T ; } interface Interface { a ( ) : Promise < WithGenerics < string > > ; } const properties = createMock < Interface > ( ) ; const interfaceCast = properties as unknown as Interface ; const result = await interfaceCast . a ( ) ; expect ( result ) . toEqual ( { generic : '' , } ) ; } ) ; it ( 'should set a promise resolved for a promise with more promise' , async ( ) => { interface WithGenerics { generic ( ) : Promise < number > ; } interface Interface { a ( ) : Promise < WithGenerics > ; } const properties = createMock < Interface > ( ) ; const interfaceCast = properties as unknown as Interface ; const result = await interfaceCast . a ( ) ; const secondPromise = await result . generic ( ) ; expect ( secondPromise ) . toBe ( 0 ) ; } ) ; it ( 'should set a promise resolved for a promise with more promise with generics' , async ( ) => { interface WithGenerics < T > { generic ( ) : Promise < T > ; generic2 ( ) : Promise < number > ; } interface Interface { a ( ) : Promise < WithGenerics < string > > ; } const properties = createMock < Interface > ( ) ; const interfaceCast = properties as unknown as Interface ; const result = await interfaceCast . a ( ) ; const secondPromise = await result . generic ( ) ; const secondPromise2 = await result . generic2 ( ) ; expect ( secondPromise ) . toBe ( '' ) ; expect ( secondPromise2 ) . toBe ( 0 ) ; } ) ; it ( 'should set a promise resolved for a promise without type' , async ( ) => { interface Interface { method ( ) : Promise ; } const properties = createMock < Interface > ( ) ; const result = await properties . method ( ) ; expect ( result ) . toBeUndefined ( ) ; } ) ; it ( 'should set a promise resolved for a promise with multiple type parameter' , async ( ) => { interface Interface < T , T2 > { a : T2 ; method ( ) : Promise < Interface < T , T2 > > ; } const properties = createMock < Interface < string , number > > ( ) ; const result = await properties . method ( ) ; expect ( result . a ) . toBe ( 0 ) ; } ) ; it ( 'should set different promises resolved for a promise with type parameter' , async ( ) => { interface Interface < T > { method ( ) : Promise < T > ; } createMock < Interface < string > > ( ) ; const propertiesReuse = createMock < Interface < number > > ( ) ; const result = await propertiesReuse . method ( ) ; expect ( result ) . toBe ( 0 ) ; } ) ; it ( 'should set a promise for multiple type reference' , async ( ) => { type B < T1 > = Promise < T1 > ; type A < T > = B < T > ; interface Interface { method ( ) : A < string > ; } const properties = createMock < Interface > ( ) ; const result = await properties . method ( ) ; expect ( result ) . toBe ( '' ) ; } ) ; it ( 'should set a promise resolved for a type mocked directly' , async ( ) => { type S < T > = Promise < T > ; const properties = createMock < S < string > > ( ) ; const result = await properties ; expect ( result ) . toBe ( '' ) ; } ) ; it ( 'should create a new Map for a Map' , ( ) => { type S < T > = Map < T , string > ; type AType = { map : Map < number , Number > ; } ; interface AnInterface { map : Map < String , string > ; } const mapMock = createMock < S < string > > ( ) ; const aType = createMock < AType > ( ) ; const anInterface = createMock < AnInterface > ( ) ; const realMap = new Map ( ) ; expect ( mapMock . constructor ) . toBe ( realMap . constructor ) ; expect ( aType . map . constructor ) . toBe ( realMap . constructor ) ; expect ( anInterface . map . constructor ) . toBe ( realMap . constructor ) ; } ) ; it ( 'should create a new Set for a Set' , ( ) => { type S < T > = Set < T > ; type AType = { mySet : Set < number > ; } ; interface AnInterface { mySet : Set < string > ; doSth ( ) : Set < string > ; } const setMock = createMock < S < string > > ( ) ; const aType = createMock < AType > ( ) ; const anInterface = createMock < AnInterface > ( ) ; const realSet = new Set ( ) ; expect ( setMock . constructor ) . toBe ( realSet . constructor ) ; expect ( aType . mySet . constructor ) . toBe ( realSet . constructor ) ; expect ( anInterface . mySet . constructor ) . toBe ( realSet . constructor ) ; expect ( anInterface . doSth ( ) . constructor ) . toBe ( realSet . constructor ) ; } ) ; it ( 'should set undefined for a not recognized type alias declaration' , ( ) => { interface WithLiteralTypescriptType { prop : InsertPosition ; } const mock = createMock < WithLiteralTypescriptType > ( ) ; expect ( mock . prop ) . toBeUndefined ( ) ; } ) ; } ) ;