@@ -9,7 +9,7 @@ import Testing
99#if canImport(Observation)
1010import Observation
1111
12- @Observable final class ObservableModel { var counter = 0 }
12+ @Observable final class ObservableModel { var counter = 0 ; var name = " " }
1313#endif
1414
1515@Suite ( " Controls and environment " )
@@ -109,5 +109,33 @@ struct ControlTests {
109109 node = host. evaluate ( )
110110 #expect( node. props [ " text " ] == . string( " count 1 " ) )
111111 }
112+
113+ @Test ( " @Bindable projects a two-way binding into an observable model " )
114+ func bindableProjection( ) {
115+ let model = ObservableModel ( )
116+ @Bindable var bound = model
117+ let binding = $bound. name
118+ binding. wrappedValue = " hi "
119+ #expect( model. name == " hi " )
120+ #expect( binding. wrappedValue == " hi " )
121+ }
122+
123+ @Test ( " A TextField bound via @Bindable writes back to the model " )
124+ func bindableTextField( ) {
125+ struct Screen : View {
126+ @Bindable var model : ObservableModel
127+ var body : some View { TextField ( " Name " , text: $model. name) }
128+ }
129+ let model = ObservableModel ( )
130+ let host = ViewHost ( Screen ( model: model) )
131+ var node = host. evaluate ( )
132+ #expect( node. props [ " text " ] == . string( " " ) )
133+ if case . int( let id) ? = node. props [ " onChange " ] {
134+ host. callbacks. invokeString ( Int64 ( id) , " Coleman " )
135+ }
136+ #expect( model. name == " Coleman " )
137+ node = host. evaluate ( )
138+ #expect( node. props [ " text " ] == . string( " Coleman " ) )
139+ }
112140 #endif
113141}
0 commit comments