generated from CodersCamp2020/CodersCamp2020.Project.TypeScript.Chess
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MNG-119 Add_player_class_tests (#41)
* Add test for too long name * Add test for too many pokemons * Add test for useMango * Add test for addPokemon function
- Loading branch information
1 parent
701e4d8
commit a054490
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}); | ||
}); |