Skip to content

Commit 8cb9c60

Browse files
committed
Update tests for previous bugfix and de-comment one test
* A socket send error should not throw an error right away - we will wait for the socket to send the error itself. * De-commented the auto-reconnect test. Use setTimeout() instead of sinon.tick()
1 parent 05b1efa commit 8cb9c60

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

test/ddp-client.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,24 @@ describe('Automatic reconnection', function() {
4949
});
5050

5151

52-
/* I am not sure why this test does not work. Something I am not doing well
53-
with clock.tick() - I am leaving it here, hoping to understand why sometime soon...
54-
55-
it('should reconnect when the connection fails', function() {
56-
var clock = sinon.useFakeTimers();
57-
58-
var ddpclient = new DDPClient();
52+
/* We should be able to get this test to work with clock.tick() but for some weird
53+
reasons it does not work. See: https://github.com/cjohansen/Sinon.JS/issues/283
54+
*/
55+
it('should reconnect when the connection fails', function(done) {
56+
var ddpclient = new DDPClient({ auto_reconnect_timer: 10 });
5957

6058
ddpclient.connect();
6159
wsMock.emit('error', {});
6260

6361
// At this point, the constructor should have been called only once.
6462
assert(wsConstructor.calledOnce);
6563

66-
// Wait 501 ms
67-
clock.tick(501);
68-
69-
// Now the constructor should have been called twice
70-
console.log("Constructor called: %s time(s)", wsConstructor.callCount);
71-
assert(wsConstructor.calledTwice);
72-
73-
clock.restore();
64+
setTimeout(function() {
65+
// Now the constructor should have been called twice
66+
assert(wsConstructor.calledTwice);
67+
done();
68+
}, 15);
7469
});
75-
*/
7670
});
7771

7872
describe("Network errors", function() {
@@ -104,8 +98,10 @@ describe("Network errors", function() {
10498

10599
ddpclient.call('aServerMethod', [42], callCB);
106100

107-
// The callback should not be called but the global socket-error event should be triggered.
101+
// The method callback should not be called
102+
// The socket-error event should not be triggered now
103+
// (but it will be triggered later by the socket)
108104
assert(!callCB.calledOnce);
109-
assert(errorCB.calledOnce);
105+
assert(!errorCB.calledOnce);
110106
});
111107
});

0 commit comments

Comments
 (0)