Skip to content

Commit

Permalink
MNG-119 Add_player_class_tests (#41)
Browse files Browse the repository at this point in the history
* Add test for too long name

* Add test for too many pokemons

* Add test for useMango

* Add test for addPokemon function
  • Loading branch information
mariusz-sm authored Feb 15, 2021
1 parent 701e4d8 commit a054490
Showing 1 changed file with 81 additions and 0 deletions.
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)
});
});

0 comments on commit a054490

Please sign in to comment.