Skip to content

Commit aac20a9

Browse files
Merge pull request 4GeeksAcademy#133 from UmiKami/10-Create_a_new_function
added unit test
2 parents 450deba + 875911d commit aac20a9

File tree

5 files changed

+29
-8
lines changed

5 files changed

+29
-8
lines changed

exercises/10-Create_a_new_function/README.es.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ En este bloque de código estamos declarando una función que recibe un argument
2424

2525
## 📝 Instrucciones:
2626

27-
1. Completa la función llamada `shortIntroduction()`, que imprima en consola una pequeña introducción de tu persona.
27+
1. Completa la función llamada `shortIntroduction()` la cual retorna una breve presentación sobre ti.
2828

2929
2. La función deberá tener 3 argumentos: `name`, `profession` y `age`.
3030

3131
3. Estos parámetros se concatenarán de la siguiente manera: `Hello! my name is {name}, my profession is {profession}. I am {age} years old.`
3232

33-
4. Por último, llama la función con los datos en el orden correcto para completar el ejercicio.
33+
4. Finalmente, dentro de un `console.log()`, llama a la función con los datos en el orden correcto para terminar el ejercicio.
3434

3535
## 💡 Pista:
3636

exercises/10-Create_a_new_function/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ In this block of code we are declaring a function which receives one argument, `
2424

2525
## 📝 Instructions:
2626

27-
1. Complete the function called `shortIntroduction()`, which prints in the console a short introduction of you.
27+
1. Complete the function called `shortIntroduction()`, which returns a short introduction of you.
2828

2929
2. The function will ask for 3 arguments: `name`, `profession`, and `age`.
3030

3131
3. They should be concatenated as follows: `Hello! my name is {name}, my profession is {profession}. I am {age} years old.`
3232

33-
4. Finally, call the function with the data in the correct order to finish the exercise.
33+
4. Finally, inside a `console.log()`, call the function with the data in the correct order to finish the exercise.
3434

3535
## 💡 Hint:
3636

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
function shortIntroduction() {
22
// Complete this function's body and arguments
3+
34
}
45

56
// Fill the gaps with your data in the correct order
6-
shortIntroduction(" ", " ", " ")
7+
console.log(shortIntroduction(" ", " ", " "))
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function shortIntroduction(name, profession, age) {
22
// Complete this function's body and arguments
3-
console.log("Hello! my name is " + name + ", my profession is " + profession + ". I am " + age + " years old.")
3+
return "Hello! my name is " + name + ", my profession is " + profession + ". I am " + age + " years old."
44
}
5-
5+
66
// Fill the gaps with your data in the correct order
7-
shortIntroduction("Carlos", "Developer", "35")
7+
console.log(shortIntroduction("Trinity", "Developer", "35"))
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const rewire = require('rewire');
4+
5+
test('shortIntroduction function exists', () => {
6+
const file = rewire("./app.js");
7+
const shortIntroduction = file.__get__('shortIntroduction');
8+
expect(typeof shortIntroduction).toBe('function');
9+
});
10+
11+
test("shortIntroduction function returns correct introduction", ()=>{
12+
13+
const file = rewire("./app.js");
14+
const shortIntroduction = file.__get__('shortIntroduction');
15+
16+
expect(shortIntroduction("Bob", "developer", 25)).toBe("Hello! my name is Bob, my profession is developer. I am 25 years old.");
17+
expect(shortIntroduction("John", "CTO", 43)).toBe("Hello! my name is John, my profession is CTO. I am 43 years old.");
18+
expect(shortIntroduction("Tom", "lead developer", 28)).toBe("Hello! my name is Tom, my profession is lead developer. I am 28 years old.");
19+
expect(shortIntroduction("Alberto", "CIO", 32)).toBe("Hello! my name is Alberto, my profession is CIO. I am 32 years old.");
20+
});

0 commit comments

Comments
 (0)