Skip to content

Commit c01dee3

Browse files
authored
Merge pull request 4GeeksAcademy#30 from ElviraQDP/master
fixing ex 10.1
2 parents 6ae4d1b + b06147f commit c01dee3

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

exercises/10.1-Creating-Your-First-Function/README.es.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
## 📝 Instrucciones:
55

6-
1. La función `add_numbers` debería devolver la suma de 2 números dados. Por favor,
7-
completa el código necesario dentro de la función para hacer que se comporte como se espera.
6+
1. La función `add_numbers` debería devolver la suma de 2 números dados. Por favor, completa el código necesario dentro de la función para hacer que se comporte como se espera.
87

98
## Resultado esperado:
109

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function addNumbers(a,b)
2+
{
3+
// This is the function body. Write your code here.
4+
}
5+
6+
//Do not change the code below
7+
console.log(addNumbers(3,4));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
jest.dontMock('fs');
5+
//here we are going to store and accumulate (concatenate) all the console log's from the exercise
6+
let _buffer = "";
7+
let _log = console.log;
8+
9+
// lets override the console.log function to mock it,
10+
// but we are also going to save what supposed to be the ouput of the console inside _buffer
11+
global.console.log = console.log = jest.fn((text) => _buffer += text + "\n");
12+
13+
describe('All the javascript should match', function () {
14+
beforeEach(() => {
15+
//here I import the HTML into the document
16+
});
17+
afterEach(() => { jest.resetModules(); });
18+
19+
it('console.log() function should be called with the sum of 3 + 4', function () {
20+
21+
22+
//then I import the index.js (which should have the alert() call inside)
23+
const file = require("./app.js");
24+
25+
//Expect the console log to have been called with the sum of 3 + 4 at least once
26+
expect(console.log).toHaveBeenCalledWith(3+4);
27+
//and I expect the console.log to be already called just one time.
28+
expect(console.log.mock.calls.length).toBe(1);
29+
30+
//You can also compare the entire console buffer (if there have been several console.log calls on the exercise)
31+
//expect(_buffer).toBe("Compare with the entire function buffer out");
32+
});
33+
});

0 commit comments

Comments
 (0)