Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNG-119_Add_player_class_tests #41

Merged
merged 4 commits into from
Feb 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions src/__tests__/playerClass.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Player } from "../playerClass";
import { Pokemon } from "../pokemonClass";
import { PokemonFactory } from "../pokemonFactory";
import * as data from "../../assets/poke_data.json";

describe("Test Player class", () => {
const pokeData = data.pokemons;
const factory = new PokemonFactory(pokeData);

const player = (name: string, pokemons: Pokemon[]) => {
return new Player(name, pokemons)
};

it("Should throw error when player name is longer than 8", () => {
// Given
const name = "Elizabeth"
const pokemonList = [
factory.getPokemonByName("bulbasaur"),
factory.getPokemonByName("charmander"),
factory.getPokemonByName("pikachu"),
]

// When
const playerWithTooLongName = () => player(name, pokemonList)

// Then
expect(playerWithTooLongName).toThrow("Too long name")
});

it("Should throw error when list of pokemons is longer than 3", () => {
// Given
const name = "Mark"
const pokemonList = [
factory.getPokemonByName("bulbasaur"),
factory.getPokemonByName("charmander"),
factory.getPokemonByName("pikachu"),
factory.getPokemonByName("squirtle")
]

// When
const playerWithTooMuchPokemens = () => player(name, pokemonList)

// Then
expect(playerWithTooMuchPokemens).toThrow("Wrong number of pokemons")
});

it("Should throw error when player has not mango", () => {
// Given
const name = "Mark"
const pokemonList = [
factory.getPokemonByName("bulbasaur"),
factory.getPokemonByName("charmander"),
factory.getPokemonByName("pikachu"),
]

// When
const playerOne = player(name, pokemonList)
const useMango = () => playerOne.useMango()
useMango()

// Then
expect(useMango).toThrow("You cannot use mango. You use all mangos")
});

it("Checks if addPokemon function works", () => {
// Given
const name = "Mark"
const pokemonList = [
factory.getPokemonByName("bulbasaur"),
factory.getPokemonByName("charmander")
]

// When
const playerOne = player(name, pokemonList)
playerOne.addPokemon(factory.getPokemonByName("squirtle"))
const numberOfPokemons = playerOne.pokemons.length

// Then
expect(numberOfPokemons).toEqual(3)
});
});