From ba9f0a586978cbddb711a274425280fd5afcd9a0 Mon Sep 17 00:00:00 2001 From: paul- <paullouis.gomis.etu@univ-lille.fr> Date: Fri, 14 Apr 2023 02:35:20 +0200 Subject: [PATCH] test player.ts --- common/player.test.ts | 21 +++++++++++++++++++++ jest.config.cjs | 5 +++++ 2 files changed, 26 insertions(+) create mode 100644 common/player.test.ts create mode 100644 jest.config.cjs diff --git a/common/player.test.ts b/common/player.test.ts new file mode 100644 index 00000000..7cfc37f4 --- /dev/null +++ b/common/player.test.ts @@ -0,0 +1,21 @@ +import { io, Socket } from "socket.io-client"; +import Player from "./Player"; +import { Sushi } from "./Ressources"; +(global as any).Image = function () {}; + +describe("sizeIncrease", () => { + it("should increase by 0.5", function () { + const p = new Player(0, 0, 20, "goku", 1, 1, "test"); + const sushis: Sushi[] = [new Sushi(0, 0, 5)]; + const socket: Socket = io(); + p.eatSushi(sushis, socket); + expect(p.radius).toBe(20.5); + }); + it("should change form every 80", function () { + const p = new Player(0, 0, 79.5, "goku", 1, 1, "test"); + const sushis: Sushi[] = [new Sushi(0, 0, 5)]; + const socket: Socket = io(); + p.eatSushi(sushis, socket); + expect(p.image.src).toBe("/images/character/goku/goku2.png"); + }); +}); diff --git a/jest.config.cjs b/jest.config.cjs new file mode 100644 index 00000000..b413e106 --- /dev/null +++ b/jest.config.cjs @@ -0,0 +1,5 @@ +/** @type {import('ts-jest').JestConfigWithTsJest} */ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', +}; \ No newline at end of file -- GitLab