Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions II.write-tests/01-greet-people/Exercise_Description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

--------------------------------------------
Exercise Description for: 01-greet-people
--------------------------------------------

The GOAL of this assignment is to test the function in './greet-people.js'.
The expected outcome is to have a list of names (which are in de array: mentors) preceeded with 'Hello'. So this would be the result when you run
the function=> greetPeople(mentors):

['Hello Irina', 'Hello Ashleigh', 'Hello Etza']

The mentors array is already in the greet-people.test.js file. You do have to think
about where to use it.

*Optional:
You can alos try to make your own array with other names to see
if the outcome is still a list of 'Hello [your array item]'.


You can look at solution file for this exercise in: "solution-greet-people.test.js"
But really try it on your own first! Try to use the solution ONLY for checking against
your own implementation.

Good luck and have fun ;-)

15 changes: 3 additions & 12 deletions II.write-tests/01-greet-people/greet-people.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
function greetPeople(people) {
var greeting = "Hello ";

people.forEach(function(person) {
greeting = greeting + person;
});

function greetPeople(people) {
const greeting = people.map(person => `Hello ${person}`);
return greeting;
}

module.exports = greetPeople;
module.exports = {greetPeople};

/*
Let's trace this piece of code - what is the value of result with this input

var mentors = ['Irina', 'Ashleigh', 'Etza'];
var result = greetPeople(mentors)
*/
8 changes: 7 additions & 1 deletion II.write-tests/01-greet-people/greet-people.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// const mentors = ['Irina', 'Ashleigh', 'Etza'];


test("print list of names prefixed with Hello", function() {
// Arrange

// Act

// Assert
});

});
10 changes: 10 additions & 0 deletions II.write-tests/01-greet-people/solution-greet-people.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const greeFuncs = require('./greet-people');

test("print list of names prefixed with Hello", function() {
// Arrange
const mentors = ['Irina', 'Ashleigh', 'Etza'];
// Act
const result = greeFuncs.greetPeople(mentors);
// Assert
expect(result).toEqual(['Hello Irina', 'Hello Ashleigh', 'Hello Etza']);
});