import { createMock } from 'ts-auto-mock' ; import { ClassDeclaration , InterfaceDeclaration , TypeDeclaration , } from '../utils/declarations/declaration' ; import { MultipleClassDeclaration , MultipleInterfaceDeclaration , MultipleLiteralTypeDeclaration , MultipleTypeDeclaration , } from '../utils/declarations/multipleDeclaration' ; describe ( 'declarations' , ( ) => { describe ( 'for one declaration' , ( ) => { describe ( 'class' , ( ) => { class MyClass { public value : 2 ; } it ( 'should return the correct properties' , ( ) => { const properties = createMock < MyClass > ( ) ; expect ( properties . value ) . toBe ( 2 ) ; } ) ; } ) ; describe ( 'interface' , ( ) => { interface Interface { value : boolean ; } it ( 'should return the correct properties' , ( ) => { const properties = createMock < Interface > ( ) ; expect ( properties . value ) . toBe ( false ) ; } ) ; } ) ; describe ( 'type' , ( ) => { type Type = { value : boolean ; } ; it ( 'should return the correct properties' , ( ) => { const properties = createMock < Type > ( ) ; expect ( properties . value ) . toBe ( false ) ; } ) ; } ) ; describe ( 'interface imported' , ( ) => { it ( 'should return the correct properties' , ( ) => { const properties = createMock < InterfaceDeclaration > ( ) ; expect ( properties . a ) . toBe ( '' ) ; } ) ; } ) ; describe ( 'class imported' , ( ) => { it ( 'should return the correct properties' , ( ) => { const properties = createMock < ClassDeclaration > ( ) ; expect ( properties . a ) . toBe ( '' ) ; } ) ; } ) ; describe ( 'type imported' , ( ) => { it ( 'should return the correct properties' , ( ) => { const properties = createMock < TypeDeclaration > ( ) ; expect ( properties . a ) . toBe ( '' ) ; } ) ; } ) ; } ) ; describe ( 'for multiple declaration' , ( ) => { describe ( 'class' , ( ) => { class MyClass { public value : 2 ; } class MyClass { public value : 3 ; public value2 : 3 ; } it ( 'should return the properties from the first declaration' , ( ) => { const properties = createMock < MyClass > ( ) ; expect ( properties . value ) . toBe ( 2 ) ; expect ( properties . value2 ) . toBeUndefined ( ) ; } ) ; } ) ; describe ( 'interface' , ( ) => { interface Interface { value : boolean ; value3 : number ; } interface Interface { value : boolean ; value2 : string ; } it ( 'should mix the properties' , ( ) => { const properties = createMock < Interface > ( ) ; expect ( properties . value ) . toBe ( false ) ; expect ( properties . value2 ) . toBe ( '' ) ; expect ( properties . value3 ) . toBe ( 0 ) ; } ) ; } ) ; describe ( 'interface and variable' , ( ) => { let Interface ; interface Interface { value : boolean ; value2 : string ; } it ( 'should ignore the variable' , ( ) => { const properties = createMock < Interface > ( ) ; expect ( properties . value ) . toBe ( false ) ; expect ( properties . value2 ) . toBe ( '' ) ; } ) ; } ) ; describe ( 'interface and namespace' , ( ) => { namespace InterfaceNamespaceTest { } interface InterfaceNamespaceTest { value : boolean ; value2 : string ; } it ( 'should ignore the namespace' , ( ) => { const properties = createMock < InterfaceNamespaceTest > ( ) ; expect ( properties . value ) . toBe ( false ) ; expect ( properties . value2 ) . toBe ( '' ) ; } ) ; } ) ; describe ( 'type' , ( ) => { type Type = { value : boolean ; } ; type Type = { value : string ; } ; it ( 'should return the first declarations properties' , ( ) => { const properties = createMock < Type > ( ) ; expect ( properties . value ) . toBe ( false ) ; } ) ; } ) ; describe ( 'function and interface' , ( ) => { interface AAA { b : number ; } function AAA ( ) { return { a : 'ss' } ; } it ( 'should return the properties from the interface' , ( ) => { const properties = createMock < AAA > ( ) ; expect ( properties . b ) . toBe ( 0 ) ; } ) ; } ) ; describe ( 'interface imported' , ( ) => { it ( 'should ignore variables declaration' , ( ) => { const properties = createMock < MultipleInterfaceDeclaration > ( ) ; expect ( properties . a ) . toBe ( '' ) ; } ) ; } ) ; describe ( 'class imported' , ( ) => { it ( 'should consider first declarations' , ( ) => { const properties = createMock < MultipleClassDeclaration > ( ) ; expect ( properties . a ) . toBe ( '' ) ; } ) ; } ) ; describe ( 'type imported' , ( ) => { it ( 'should return the correct properties' , ( ) => { const properties = createMock < MultipleTypeDeclaration > ( ) ; expect ( properties . a ) . toBe ( '' ) ; } ) ; } ) ; describe ( 'literal imported' , ( ) => { it ( 'should return the correct properties' , ( ) => { interface Interface { test : MultipleLiteralTypeDeclaration ; } const properties = createMock < Interface > ( ) ; expect ( properties . test ) . toBe ( 'string' ) ; } ) ; } ) ; } ) ; } ) ;