-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
31 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,37 @@ | ||
import _reconnect from "./index.js"; | ||
import { EventEmitter } from "@xmpp/events"; | ||
// eslint-disable-next-line n/no-extraneous-import | ||
import Connection from "@xmpp/connection"; | ||
|
||
test("it schedule a reconnect when disconnect is emitted", (done) => { | ||
const entity = new EventEmitter(); | ||
test("schedules a reconnect when disconnect is emitted", () => { | ||
const entity = new Connection(); | ||
const reconnect = _reconnect({ entity }); | ||
const spy_scheduleReconnect = jest.spyOn(reconnect, "scheduleReconnect"); | ||
|
||
reconnect.scheduleReconnect = () => { | ||
expect.pass(); | ||
done(); | ||
}; | ||
|
||
expect(spy_scheduleReconnect).toHaveBeenCalledTimes(0); | ||
entity.emit("disconnect"); | ||
expect(spy_scheduleReconnect).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test("#reconnect", async () => { | ||
expect.assertions(3); | ||
|
||
const entity = new EventEmitter(); | ||
const service = "service"; | ||
const lang = "lang"; | ||
const domain = "domain"; | ||
|
||
const entity = new Connection({ | ||
service, | ||
lang, | ||
domain, | ||
}); | ||
const reconnect = _reconnect({ entity }); | ||
|
||
entity.options = { | ||
service: "service", | ||
lang: "lang", | ||
domain: "domain", | ||
}; | ||
|
||
entity.connect = (service) => { | ||
expect(service).toBe(entity.options.service); | ||
}; | ||
|
||
entity.open = ({ domain, lang }) => { | ||
expect(domain).toBe(entity.options.domain); | ||
expect(lang).toBe(entity.options.lang); | ||
}; | ||
const spy_connect = jest.spyOn(entity, "connect").mockResolvedValue(); | ||
const spy_open = jest.spyOn(entity, "open").mockResolvedValue(); | ||
|
||
await reconnect.reconnect(); | ||
|
||
expect(spy_connect).toHaveBeenCalledWith(service); | ||
expect(spy_open).toHaveBeenCalledWith({ | ||
domain, | ||
lang, | ||
}); | ||
}); |