/**
 * Copyright (c) 2016-2017 Dmitry Panyushkin
 * Available under MIT license
 */ Symbol = undefined as any ; import * as ko from "knockout" ; import { observable , unwrap } from "../src/knockout-decorators" ; describe ( "@observable({ deep: true, expose: true }) decorator" , ( ) => { it ( "should combine deep observable objects and arrays" , ( ) => { class ViewModel { @ observable ( { deep : true , expose : true } ) deepObservable = { firstName : "Clive Staples" , lastName : "Lewis" , array : [ ] as any [ ] , object : { foo : "bar" , reference : null as object | null , } , } ; } const vm = new ViewModel ( ) ; vm . deepObservable . array . push ( { firstName : "Clive Staples" , lastName : "Lewis" , } ) ; vm . deepObservable . object . reference = { firstName : "Clive Staples" , lastName : "Lewis" , } ; expect ( ko . isObservable ( unwrap ( vm , "deepObservable" ) ) ) . toBeTruthy ( ) ; expect ( ko . isObservable ( vm . _deepObservable ) ) . toBeTruthy ( ) ; expect ( vm . _deepObservable ) . toBe ( unwrap ( vm , "deepObservable" ) ) ; expect ( ko . isObservable ( unwrap ( vm . deepObservable , "firstName" ) ) ) . toBeTruthy ( ) ; expect ( ko . isObservable ( vm . deepObservable . _firstName ) ) . toBeTruthy ( ) ; expect ( vm . deepObservable . _firstName ) . toBe ( unwrap ( vm . deepObservable , "firstName" ) ) ; expect ( ko . isObservable ( unwrap ( vm . deepObservable , "lastName" ) ) ) . toBeTruthy ( ) ; expect ( ko . isObservable ( vm . deepObservable . _lastName ) ) . toBeTruthy ( ) ; expect ( vm . deepObservable . _lastName ) . toBe ( unwrap ( vm . deepObservable , "lastName" ) ) ; expect ( ko . isObservable ( unwrap ( vm . deepObservable , "array" ) ) ) . toBeTruthy ( ) ; expect ( ko . isObservable ( vm . deepObservable . _array ) ) . toBeTruthy ( ) ; expect ( ko . isObservable ( unwrap ( vm . deepObservable . array [ 0 ] , "firstName" ) ) ) . toBeTruthy ( ) ; expect ( ko . isObservable ( vm . deepObservable . array [ 0 ] . _firstName ) ) . toBeTruthy ( ) ; expect ( ko . isObservable ( unwrap ( vm . deepObservable . array [ 0 ] , "lastName" ) ) ) . toBeTruthy ( ) ; expect ( ko . isObservable ( vm . deepObservable . array [ 0 ] . _lastName ) ) . toBeTruthy ( ) ; expect ( ko . isObservable ( unwrap ( vm . deepObservable , "object" ) ) ) . toBeTruthy ( ) ; expect ( ko . isObservable ( vm . deepObservable . _object ) ) . toBeTruthy ( ) ; expect ( ko . isObservable ( unwrap ( vm . deepObservable . object , "foo" ) ) ) . toBeTruthy ( ) ; expect ( ko . isObservable ( vm . deepObservable . object . _foo ) ) . toBeTruthy ( ) ; expect ( ko . isObservable ( unwrap ( vm . deepObservable . object , "reference" ) ) ) . toBeTruthy ( ) ; expect ( ko . isObservable ( vm . deepObservable . object . _reference ) ) . toBeTruthy ( ) ; expect ( ko . isObservable ( unwrap ( vm . deepObservable . object . reference , "firstName" ) ) ) . toBeTruthy ( ) ; expect ( ko . isObservable ( vm . deepObservable . object . reference . _firstName ) ) . toBeTruthy ( ) ; expect ( ko . isObservable ( unwrap ( vm . deepObservable . object . reference , "lastName" ) ) ) . toBeTruthy ( ) ; expect ( ko . isObservable ( vm . deepObservable . object . reference . _lastName ) ) . toBeTruthy ( ) ; } ) ; it ( "should be serializable to JSON" , ( ) => { class ViewModel { @ observable ( { deep : true , expose : true } ) object = { property : "test" , reference : { nested : 123 , } , array : [ { x : 0 , y : 0 } , ] , } ; } const vm = new ViewModel ( ) ; const json = JSON . stringify ( vm ) ; expect ( json ) . toBe ( '{"object":{"property":\"test\","reference":{"nested":123},"array":[{"x":0,"y":0}]}}' ) ; } ) ; } ) ;