-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathfunctions.test.js
97 lines (77 loc) · 2.29 KB
/
functions.test.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
describe('DAY 6: Test Functions', () => {
it(`(function statement)
declare a function named hello`, () => {
// add your code here
expect(hello).toBeInstanceOf(Function);
});
it(`(anonymous function expression)
write an anonymous function expression with an empty body`, () => {
// add your code here
expect(hello).toBeInstanceOf(Function);
expect(hello.toString().replace(/[^a-z0-9_$]/igm, '')).toBe('function');
});
it(`(named function expression)
write a named function expression with an empty body`, () => {
// add your code here
expect(hello).toBeInstanceOf(Function);
expect(hello.toString().replace(/[^a-z0-9_$]/igm, '')).toMatch(/^function[a-z0-9_$]+$/);
});
it(`(IIFE)
convert function a into an IIFE`, () => {
let a = 1;
// add your code here
// there's probably no way to verify with a test if it's an IIFE
// use this to learn, not to pass the test :P
/**
* @returns {undefined}
*/
function b () {
a++;
}
expect(a).toBe(2);
});
it(`(Function arity)
get the function's arity and assign it to the arity variable to match the test`, () => {
/**
*
* @param {*} b
* @param {*} c
* @param {*} d
* @param {*} e
* @returns {undefined}
*/
function a (b, c, d, e) {}
// add your code here
let arity;
expect(arity).toBe(4);
});
it(`(Properties of a function)
get the name of myFunction`, () => {
/**
*
* @returns {undefined}
*/
function myFunction () { }
// change the test
expect(myFunction).toBe('myFunction');
});
it(`(Side effect)
change to code to avoid function b to have side effects on a`, () => {
let a = 1;
/**
*
* @param {*} b
* @returns {undefined}
*/
function b () {
// add your code here
a = 2;
return ++a;
}
expect(a).toBe(1);
expect(b()).toBe(3);
// intentional repetition
expect(a).toBe(1);
expect(b()).toBe(3);
});
});