Skip to content

Commit 3679b7c

Browse files
committed
Added onConnect tests
1 parent 3811c8d commit 3679b7c

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

test/test.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,34 @@ describe('CrossStorageClient', function() {
115115
storage.onConnect().then(done);
116116
});
117117

118-
it('is not fulfilled if a connection is not established', function(done) {
118+
it('rejects if no connection could be established', function(done) {
119119
var storage = new CrossStorageClient('http://localhost:9999');
120-
var invoked = false;
121120

122-
storage.onConnect().then(function() {
123-
invoked = true;
121+
storage.onConnect()['catch'](function(err) {
122+
expect(err.message).to.be('CrossStorageClient could not connect');
123+
done();
124124
});
125+
});
126+
127+
it('can be used multiple times prior to connection', function(done) {
128+
var storage, count, incrOnConnect, i;
129+
130+
storage = new CrossStorageClient(url);
131+
count = 0;
132+
incrOnConnect = function() {
133+
storage.onConnect().then(function() {
134+
count++;
135+
});
136+
};
125137

126-
setTimeout(function() {
127-
if (!invoked) return done();
138+
for (i = 0; i < 5; i++) {
139+
incrOnConnect();
140+
}
128141

129-
done(new Error('onConnect fired without connecting'));
130-
}, 100);
142+
storage.onConnect().then(function() {
143+
expect(count).to.be(5);
144+
done();
145+
});
131146
});
132147
});
133148

0 commit comments

Comments
 (0)