-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.arguments.test.js
More file actions
67 lines (65 loc) · 2.91 KB
/
default.arguments.test.js
File metadata and controls
67 lines (65 loc) · 2.91 KB
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
const defaultArguments = require("./default.arguments");
describe('default arguments test with normal function',() => {
function combineNames (firstName, lastName) {
return `${firstName} ${lastName}`;
}
it('should default first name', () => {
const combineNamesFunc = defaultArguments(combineNames,{firstName: 'John'});
const fullName = combineNamesFunc(undefined,'Cena')
expect(fullName).toBe('John Cena');
});
it('should default last name', () => {
const combineNamesFunc = defaultArguments(combineNames,{lastName: 'Buzova'});
const fullName = combineNamesFunc('Olga')
expect(fullName).toBe('Olga Buzova');
});
it('should default fullname', () => {
const combineNamesFunc = defaultArguments(combineNames,{firstName: 'Alan',lastName: 'Walker'});
const fullName = combineNamesFunc()
expect(fullName).toBe('Alan Walker');
});
it('should not default fullname when params are passed', () => {
const combineNamesFunc = defaultArguments(combineNames,{firstName: 'Alan',lastName: 'Walker'});
const fullName = combineNamesFunc('Vera','Brezhneva')
expect(fullName).not.toBe('Alan Walker');
expect(fullName).toBe('Vera Brezhneva');
});
it('should not default fullname when object does not have arguments', () => {
const combineNamesFunc = defaultArguments(combineNames,{fullName: 'Alan Walker'});
const fullName = combineNamesFunc()
expect(fullName).not.toBe('Alan Walker');
expect(fullName).toBe('undefined undefined');
});
})
describe('default arguments test with arrow function',() => {
const combineNames = (firstName, lastName) => {
return `${firstName} ${lastName}`;
}
it('should default first name', () => {
const combineNamesFunc = defaultArguments(combineNames,{firstName: 'John'});
const fullName = combineNamesFunc(undefined,'Cena')
expect(fullName).toBe('John Cena');
});
it('should default last name', () => {
const combineNamesFunc = defaultArguments(combineNames,{lastName: 'Buzova'});
const fullName = combineNamesFunc('Olga')
expect(fullName).toBe('Olga Buzova');
});
it('should default fullname', () => {
const combineNamesFunc = defaultArguments(combineNames,{firstName: 'Alan',lastName: 'Walker'});
const fullName = combineNamesFunc()
expect(fullName).toBe('Alan Walker');
});
it('should not default fullname when params are passed', () => {
const combineNamesFunc = defaultArguments(combineNames,{firstName: 'Alan',lastName: 'Walker'});
const fullName = combineNamesFunc('Vera','Brezhneva')
expect(fullName).not.toBe('Alan Walker');
expect(fullName).toBe('Vera Brezhneva');
});
it('should not default fullname when object does not have arguments', () => {
const combineNamesFunc = defaultArguments(combineNames,{fullName: 'Alan Walker'});
const fullName = combineNamesFunc()
expect(fullName).not.toBe('Alan Walker');
expect(fullName).toBe('undefined undefined');
});
})