slaywithfriends/src/cards.test.js

43 lines
1.3 KiB
JavaScript

import { beforeAll, describe, expect, test } from "bun:test";
import { getAllCards, getCard, getStarterDeck, initCards } from "./cards.js";
beforeAll(async () => {
await initCards();
});
describe("cards", () => {
test("getCard returns card by id", () => {
const card = getCard("strike_r");
expect(card.name).toBe("Strike");
expect(card.cost).toBe(1);
expect(card.type).toBe("attack");
expect(card.effects[0].type).toBe("hit");
});
test("getCard returns undefined for unknown id", () => {
expect(getCard("nonexistent")).toBeUndefined();
});
test("getStarterDeck returns 10 card ids for ironclad", () => {
const deck = getStarterDeck("ironclad");
expect(deck).toHaveLength(10);
expect(deck.filter((id) => id === "strike_r")).toHaveLength(5);
expect(deck.filter((id) => id === "defend_r")).toHaveLength(4);
expect(deck.filter((id) => id === "bash")).toHaveLength(1);
});
});
describe("getAllCards", () => {
test("returns array with more than 100 cards", () => {
const cards = getAllCards();
expect(cards.length).toBeGreaterThan(100);
});
test("each card has id and name properties", () => {
const cards = getAllCards();
for (const card of cards) {
expect(card.id).toBeDefined();
expect(card.name).toBeDefined();
}
});
});