import { assertJSON } from '../../../test/Assertions' ; import { assert } from 'chai' ; describe ( 'Custom objects from JSON' , function ( ) { it ( "No custom constructor" , function ( ) { class Address { public readonly city ? : string ; public readonly state ? : string ; public readonly zip ? : string ; } let address = Object . assign ( new Address ( ) , { city : "San Francisco" , state : "California" , zip : 94107 } ) ; assert . equal ( address . constructor . name , "Address" ) ; let expected = { "city" : "San Francisco" , "state" : "California" , "zip" : 94107 } ; assertJSON ( address , expected ) ; } ) ; it ( "Test of single interface object from JSON" , function ( ) { interface Address { readonly city : string ; readonly state : string ; readonly zip : number ; } let address = { city : "San Francisco" , state : "California" , zip : 94107 } ; let expected = { "city" : "San Francisco" , "state" : "California" , "zip" : 94107 } ; assertJSON ( address , expected ) ; } ) ; it ( "Test of single interface object from JSON" , function ( ) { interface Address { readonly city : string ; readonly state : string ; readonly zip : number ; } let address = [ { city : "San Francisco" , state : "California" , zip : 94107 } ] ; let expected = [ { "city" : "San Francisco" , "state" : "California" , "zip" : 94107 } ] ; assertJSON ( address , expected ) ; } ) ; it ( "type promotion and methods" , function ( ) { class Address { readonly city : string ; readonly state : string ; readonly zip : number ; constructor ( city , state , zip ) { this . city = city ; this . state = state ; this . zip = zip ; } format ( ) { return `${ this . city }, ${ this . state } ${ this . zip }` ; } } let address ; address = new Address ( "San Francisco" , "CA" , 94107 ) ; assert . equal ( address . constructor . name , "Address" ) ; assert . notEqual ( address . format , null ) ; address = < Address > { } ; console . log ( address . city ) ; } ) ; } ) ;