@@ -90,4 +90,43 @@ describe('client connection', function() {
90
90
} ) ;
91
91
} ) ;
92
92
93
+ describe ( 'state management using setSocket' , function ( ) {
94
+ it ( 'initial state is connecting' , function ( ) {
95
+ var connection = this . backend . connect ( ) ;
96
+ expect ( connection . state ) . equal ( 'connecting' ) ;
97
+ } ) ;
98
+
99
+ it ( 'after connected event is emitted, state is connected' , function ( done ) {
100
+ var connection = this . backend . connect ( ) ;
101
+ connection . on ( 'connected' , function ( ) {
102
+ expect ( connection . state ) . equal ( 'connected' ) ;
103
+ done ( ) ;
104
+ } ) ;
105
+ } ) ;
106
+
107
+ it ( 'when connection is manually closed, state is closed' , function ( done ) {
108
+ var connection = this . backend . connect ( ) ;
109
+ connection . on ( 'connected' , function ( ) {
110
+ connection . close ( ) ;
111
+ } ) ;
112
+ connection . on ( 'closed' , function ( ) {
113
+ expect ( connection . state ) . equal ( 'closed' ) ;
114
+ done ( ) ;
115
+ } ) ;
116
+ } ) ;
117
+
118
+ it ( 'when connection is disconnected, state is disconnected' , function ( done ) {
119
+ var connection = this . backend . connect ( ) ;
120
+ connection . on ( 'connected' , function ( ) {
121
+ // Mock a disconnection by providing a reason
122
+ connection . socket . close ( 'foo' ) ;
123
+ } ) ;
124
+ connection . on ( 'disconnected' , function ( ) {
125
+ expect ( connection . state ) . equal ( 'disconnected' ) ;
126
+ done ( ) ;
127
+ } ) ;
128
+ } ) ;
129
+
130
+ } ) ;
131
+
93
132
} ) ;
0 commit comments