2019-05-22 03:37:03 +00:00
|
|
|
import { expect } from "chai";
|
|
|
|
import { Offline } from "test/helper/Offline";
|
|
|
|
import { Transport } from "./Transport";
|
|
|
|
import { TransportEvent } from "./TransportEvent";
|
|
|
|
|
|
|
|
describe("TransportEvent", () => {
|
|
|
|
|
|
|
|
it("can be created and disposed", () => {
|
|
|
|
return Offline((context) => {
|
2019-09-16 03:32:40 +00:00
|
|
|
const transport = new Transport({ context });
|
2019-05-22 03:37:03 +00:00
|
|
|
const event = new TransportEvent(transport, {
|
|
|
|
time: 0,
|
|
|
|
});
|
|
|
|
event.dispose();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("has a unique id", () => {
|
|
|
|
return Offline((context) => {
|
2019-09-16 03:32:40 +00:00
|
|
|
const transport = new Transport({ context });
|
2019-05-22 03:37:03 +00:00
|
|
|
const event = new TransportEvent(transport, {
|
|
|
|
time: 0,
|
|
|
|
});
|
|
|
|
expect(event.id).to.be.a("number");
|
|
|
|
event.dispose();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-06-19 21:20:12 +00:00
|
|
|
it("can invoke the callback", () => {
|
|
|
|
let wasInvoked = false;
|
|
|
|
return Offline((context) => {
|
2019-09-16 03:32:40 +00:00
|
|
|
const transport = new Transport({ context });
|
2019-05-22 03:37:03 +00:00
|
|
|
const event = new TransportEvent(transport, {
|
|
|
|
callback: (time) => {
|
|
|
|
expect(time).to.equal(100);
|
2019-06-19 21:20:12 +00:00
|
|
|
wasInvoked = true;
|
2019-05-22 03:37:03 +00:00
|
|
|
},
|
|
|
|
time: 0,
|
|
|
|
});
|
|
|
|
event.invoke(100);
|
2019-06-19 21:20:12 +00:00
|
|
|
}).then(() => {
|
|
|
|
expect(wasInvoked).to.equal(true);
|
2019-05-22 03:37:03 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|