Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Jun 20, 2023
1 parent cf9a50b commit baed014
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
16 changes: 9 additions & 7 deletions lib/manager.ts
Expand Up @@ -328,19 +328,21 @@ export class Manager<
fn && fn();
});

// emit `error`
const errorSub = on(socket, "error", (err) => {
const onError = (err) => {
debug("error");
self.cleanup();
self._readyState = "closed";
this.cleanup();
this._readyState = "closed";
this.emitReserved("error", err);
if (fn) {
fn(err);
} else {
// Only do this if there is no fn to handle the error
self.maybeReconnectOnOpen();
this.maybeReconnectOnOpen();
}
});
};

// emit `error`
const errorSub = on(socket, "error", onError);

if (false !== this._timeout) {
const timeout = this._timeout;
Expand All @@ -354,7 +356,7 @@ export class Manager<
const timer = this.setTimeoutFn(() => {
debug("connect attempt timed out after %d", timeout);
openSubDestroy();
this.onerror(new Error("timeout"));
onError(new Error("timeout"));
socket.close();
}, timeout);

Expand Down
4 changes: 2 additions & 2 deletions test/socket.ts
Expand Up @@ -75,7 +75,7 @@ describe("socket", () => {
const socket = io(BASE_URL, {
forceNew: true,
transports: ["polling"],
timeout: 5,
timeout: 1,
});
socket.on("connect_error", (err) => {
expect(err.message).to.eql("timeout");
Expand All @@ -90,7 +90,7 @@ describe("socket", () => {
const socket = io(BASE_URL, {
forceNew: true,
transports: ["websocket"],
timeout: 5,
timeout: 1,
});
socket.on("connect_error", (err) => {
expect(err.message).to.eql("timeout");
Expand Down

0 comments on commit baed014

Please sign in to comment.