-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathclosure.test.js
More file actions
43 lines (32 loc) · 995 Bytes
/
Copy pathclosure.test.js
File metadata and controls
43 lines (32 loc) · 995 Bytes
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
describe('DAY 6: Test closure', () => {
it(`function a to change variable b through a closure (side effect)`, () => {
/**
*
* @returns {undefined}
*/
function a () {
// add the code to operate with the free variable
b++;
}
let b = 5;
// add the code to execute the operation on the free variable inside function a
expect(b).toBe(6);
});
it(`function c to change variable a and b through a closure (side effect)`, () => {
let a = 9;
let b = function () {};
/**
*
* @returns {undefined}
*/
function c () {
a = function () {};
b = [];
}
expect(typeof a).toBe('number');
expect(b).toBeInstanceOf(Function);
// add the missing part of the code to complete the test
expect(typeof a).toBe('function');
expect(b).toBeInstanceOf(Array);
});
});