generated from JoinCODED/TASK-Template
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathfunctions.test.js
72 lines (60 loc) · 1.61 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
const { faker } = require("@faker-js/faker");
const { printName, printAge, printHello, printMax } = require("./functions");
test("printName function", () => {
const spy = jest.spyOn(console, "log");
const names = Array(10)
.fill(0)
.map(() => faker.person.firstName());
names.forEach((name) => {
printName(name);
expect(spy).toHaveBeenCalledWith(name);
});
spy.mockRestore();
});
test("printAge function", () => {
const spy = jest.spyOn(console, "log");
const birthYears = Array(10)
.fill(0)
.map(() =>
new Date(
faker.date.birthdate({ mode: "age", min: 5, max: 100 })
).getFullYear()
);
birthYears.forEach((YOB) => {
printAge(YOB);
expect(spy).toHaveBeenCalledWith(new Date().getFullYear() - YOB);
});
});
test("printHello function", () => {
const spy = jest.spyOn(console, "log");
const names = Array(10)
.fill(0)
.map(() => faker.person.firstName());
const languages = {
en: "Hello",
es: "Hola",
fr: "Bonjour",
tr: "Merhaba",
};
names.forEach((name) => {
Object.keys(languages).forEach((language) => {
printHello(name, language);
expect(spy).toHaveBeenCalledWith(`${languages[language]} ${name}`);
});
});
spy.mockRestore();
});
test("printMax Function", () => {
const spy = jest.spyOn(console, "log");
const numbers = Array(10)
.fill(0)
.map(() => [
faker.number.int({ min: 0, max: 100 }),
faker.number.int({ min: 0, max: 100 }),
]);
numbers.forEach((nums) => {
printMax(...nums);
expect(spy).toHaveBeenCalledWith(Math.max(...nums));
});
spy.mockRestore();
});