Skip to content

Commit 8081057

Browse files
author
rachael
committed
Add tests for connection state management
1 parent 186e9d7 commit 8081057

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/client/connection.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,43 @@ describe('client connection', function() {
9090
});
9191
});
9292

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+
93132
});

0 commit comments

Comments
 (0)