-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create test for createDeferredListener
- Loading branch information
1 parent
5a28336
commit 933a774
Showing
1 changed file
with
28 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import sinon from "sinon"; | ||
import { createDeferredListener } from "../src/listener"; | ||
|
||
describe("createDeferredListener", () => { | ||
it("queues calls to the listener", async () => { | ||
const { setListener, listener } = createDeferredListener(); | ||
const spy = sinon.spy(); | ||
|
||
// Trigger a couple of events | ||
listener("message", "sender", "sendResponse"); | ||
listener("message2", "sender2", "sendResponse2"); | ||
|
||
// Listener should receive previous messages | ||
setListener(spy); | ||
|
||
// Trigger more events | ||
listener("message3", "sender3", "sendResponse3"); | ||
listener("message4", "sender4", "sendResponse4"); | ||
|
||
await Promise.resolve(); | ||
|
||
spy.callCount.should.equal(4); | ||
spy.getCall(0).args.should.eql(["message", "sender", "sendResponse"]); | ||
spy.getCall(1).args.should.eql(["message2", "sender2", "sendResponse2"]); | ||
spy.getCall(2).args.should.eql(["message3", "sender3", "sendResponse3"]); | ||
spy.getCall(3).args.should.eql(["message4", "sender4", "sendResponse4"]); | ||
}); | ||
}); |