Skip to content

Commit

Permalink
Fix npm tests
Browse files Browse the repository at this point in the history
  • Loading branch information
meghanmae committed May 18, 2024
1 parent 185d291 commit 63f092e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
43 changes: 43 additions & 0 deletions wordle-web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions wordle-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"devDependencies": {
"@nuxt/test-utils": "^3.12.0",
"@vue/test-utils": "^2.4.5",
"axios-mock-adapter": "^1.22.0",
"happy-dom": "^13.10.1",
"playwright-core": "^1.43.0",
"vite-plugin-vuetify": "^2.0.3",
Expand Down
27 changes: 24 additions & 3 deletions wordle-web/tests/game.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
// @vitest-environment nuxt
import { expect, test } from "vitest";
import { beforeEach, expect, test } from "vitest";
import { Game } from "~/scripts/game";
import { LetterState } from "~/scripts/letter";
import AxiosMockAdapter from "axios-mock-adapter";
import axios from "axios";
import { GameStats } from "~/scripts/gameStats";

let mock: AxiosMockAdapter;

beforeEach(() => {
mock = new AxiosMockAdapter(axios);
});

test("game", () => {
// create game and check if it's created
Expand All @@ -12,7 +21,19 @@ test("game", () => {

test("guess-word", () => {
const game = new Game();
game.startNewGame("autos");

const word = "autos";

const mockGameStats = new GameStats();
mockGameStats.word = "autos";
mockGameStats.averageGuesses = 0;
mockGameStats.totalTimesPlayed = 0;
mockGameStats.totalWins = 0;
mockGameStats.totalLosses = 0;

mock.onPost().reply(200, mockGameStats);

game.startNewGame(word);
game.setGuessLetters("tangs");
game.submitGuess();
expect(game.guesses[0].letters[0].state).toBe(LetterState.Misplaced);
Expand All @@ -21,7 +42,7 @@ test("guess-word", () => {
expect(game.guesses[0].letters[3].state).toBe(LetterState.Wrong);
expect(game.guesses[0].letters[4].state).toBe(LetterState.Correct);

game.setGuessLetters("autos");
game.setGuessLetters(word);
game.submitGuess();
expect(game.guesses[1].letters[0].state).toBe(LetterState.Correct);
expect(game.guesses[1].letters[1].state).toBe(LetterState.Correct);
Expand Down

0 comments on commit 63f092e

Please sign in to comment.