describe("World", () => {
it("should connect user1 and user2", () => {
- let connectCalled: boolean = false;
+ let connectCalledNumber: number = 0;
let connect = (user: string, group: Group): void => {
- connectCalled = true;
+ connectCalledNumber++;
}
let disconnect = (user: string, group: Group): void => {
position: new Point(261, 100)
}));
- expect(connectCalled).toBe(false);
+ expect(connectCalledNumber).toBe(0);
world.updatePosition(new MessageUserPosition({
userId: "bar",
position: new Point(101, 100)
}));
- expect(connectCalled).toBe(true);
+ expect(connectCalledNumber).toBe(2);
- connectCalled = false;
world.updatePosition(new MessageUserPosition({
userId: "bar",
roomId: 1,
position: new Point(102, 100)
}));
- expect(connectCalled).toBe(false);
+ expect(connectCalledNumber).toBe(2);
});
it("should connect 3 users", () => {
it("should disconnect user1 and user2", () => {
let connectCalled: boolean = false;
- let disconnectCalled: boolean = false;
+ let disconnectCallNumber: number = 0;
let connect = (user: string, group: Group): void => {
connectCalled = true;
}
let disconnect = (user: string, group: Group): void => {
- disconnectCalled = true;
+ disconnectCallNumber++;
}
let world = new World(connect, disconnect);
}));
expect(connectCalled).toBe(true);
- expect(disconnectCalled).toBe(false);
+ expect(disconnectCallNumber).toBe(0);
world.updatePosition(new MessageUserPosition({
userId: "bar",
position: new Point(100+160+160+1, 100)
}));
- expect(disconnectCalled).toBe(true);
+ expect(disconnectCallNumber).toBe(2);
- disconnectCalled = false;
world.updatePosition(new MessageUserPosition({
userId: "bar",
roomId: 1,
position: new Point(262, 100)
}));
- expect(disconnectCalled).toBe(false);
+ expect(disconnectCallNumber).toBe(2);
});
})