-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path1.map-filter-find.test.js
More file actions
55 lines (49 loc) · 1.82 KB
/
1.map-filter-find.test.js
File metadata and controls
55 lines (49 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const pokemons = require("./pokeData");
const {
getPokeNames,
getPokemonById,
getRarePokemons,
getMidSizedPokemon,
getAdultPokemons,
getPokemonImages,
} = require("./1.map-filter-find");
test("getPokeNames: Transforms an array of pokemons into an array of pokemon names", () => {
const pokemonNames = getPokeNames();
expect(pokemonNames.length).toBe(151);
expect(pokemonNames[0]).toBe("Bulbasaur");
expect(pokemonNames[pokemonNames.length - 1]).toBe("Mew");
});
test("getPokemonById: Gets a pokemon object by their id", () => {
const id = 25;
const pokemon = getPokemonById(id);
expect(pokemon).toEqual(
expect.objectContaining({
id: expect.any(Number),
name: expect.any(String),
height: expect.any(String),
})
);
expect(pokemon.id).toBe(25);
expect(pokemon.name).toBe("Pikachu");
expect(pokemon.height).toBe("0.41 m");
});
test('getRarePokemons: Transforms an array of pokemon into an array of "rare" (spawn_chance is less than 0.1) pokemon', () => {
const rarePokemon = getRarePokemons();
expect(rarePokemon.length).toBe(81);
expect(rarePokemon.every((pokemon) => pokemon.spawn_chance < 0.1)).toBe(true);
});
test('getMidSizedPokemon: Gets the pokemon that weighs "38.0 kg"', () => {
const pokeMonThatWeighs38kg = getMidSizedPokemon();
expect(pokeMonThatWeighs38kg.name).toBe("Fearow");
});
test("getAdultPokemons: Transforms an array of pokemon into an array of pokemon who cannot be found in eggs", () => {
const adults = getAdultPokemons();
expect(adults.length).toBe(78);
expect(adults.every((pokemon) => pokemon.egg === "Not in Eggs")).toBe(true);
});
test("getPokemonImages: Transforms an array of pokemon into an array of imageUrls", () => {
const imageUrls = getPokemonImages();
imageUrls.forEach((imageUrl) => {
expect(typeof imageUrl).toBe("string");
});
});