Skip to content
Snippets Groups Projects
Commit a6c9bea0 authored by Ait Lamine Ilias's avatar Ait Lamine Ilias
Browse files

test: test unitaire. Ref #4

parent 255ec194
No related branches found
No related tags found
1 merge request!9test: test unitaire. Ref #4
import {fetchPokemonList} from './pokemonProvider.js';
function getPokemons(pokemons) {
const list = pokemons;
console.log(list);
function filterPokemons(pokemons) {
return pokemons.filter(pokemon => pokemon.weight > 3 && pokemon.height < 1);
}
/**
* Filter Pokémon with weight > 3kg and height < 1m
*/
function filterPokemons() {
fetchPokemonList((pokemons) => {
const filteredPokemons = pokemons.filter(pokemon => pokemon.weight > 3 );
displayPokemons(filteredPokemons);
}, 318); // Fetch 318 Pokémon
}
function filterPokemons2() {
fetchPokemonList((pokemons) => {
const filteredPokemons = pokemons.filter(pokemon => pokemon.height < 1 );
displayPokemons(filteredPokemons);
}, 318); // Fetch 318 Pokémon
}
fetchPokemonList(getPokemons, 20);
\ No newline at end of file
module.exports = filterPokemons;
\ No newline at end of file
const convert = require('./convert');
// filterPokemons.test.js
const filterPokemons = require('./filtrage'); // Import your filter function
test('Conversion Euros to Dollars', () => {
expect(convert.convertEurToUsd(3)).toBe(3.114);
});
test('filters Pokémon with weight > 3kg and height < 1m', () => {
const pokemons = [
{ name: 'Pikachu', weight: 6, height: 0.4 },
{ name: 'Bulbasaur', weight: 3, height: 0.7 },
{ name: 'Squirtle', weight: 4, height: 0.9 },
{ name: 'Charizard', weight: 10, height: 1.7 }
];
const filteredPokemons = filterPokemons(pokemons);
// Assert that the filtered list contains only the valid Pokémon
expect(filteredPokemons).toEqual([
{ name: 'Pikachu', weight: 6, height: 0.4 },
{ name: 'Squirtle', weight: 4, height: 0.9 }
]);
});
\ No newline at end of file
......@@ -5,7 +5,7 @@
"main": "pokemonProvider.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest"
},
"keywords": [],
"author": "",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment