Repository navigation
Expand file tree
/
Copy pathtests.js
More file actions
44 lines (38 loc) · 1.64 KB
/
Copy pathtests.js
File metadata and controls
44 lines (38 loc) · 1.64 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
const rewire = require('rewire');
const fs = require('fs');
test('The Function "sortNames" should exist', () => {
const app = rewire('./app.js');
const sortNames = app.__get__('sortNames');
expect(sortNames).toBeTruthy()
})
test('Function "sortNames" should return something', function(){
const file = rewire("./app.js");
const list = ['Jhon','Lucas']
const sortNames = file.__get__('sortNames');
expect(sortNames(list)).toBeTruthy()
});
test('The function should return an array', () => {
const file = rewire('./app.js')
const sortNames = file.__get__('sortNames')
let arr = ['sadiel','james','saikel'];
expect(Array.isArray(sortNames(arr))).toBe(true)
})
test('The function should use the sort method to sort the arrays', () => {
const fileContent = fs.readFileSync('./exercises/09-Array-Methods/app.js');
const regex = /\w+\.sort\(/gm;
expect(regex.exec(fileContent)).toBeTruthy();
})
test('The function should sort the array and then return the array sorted', () => {
const file = rewire("./app.js");
const sortNames = file.__get__('sortNames');
let names = ['Tomas', 'Alejandro', 'Jake', "Mark"];
let sortedNames = ['Alejandro', 'Jake', 'Mark', 'Tomas'];
expect(sortNames(names)).toEqual(sortedNames);
});
test('The function should sort the array and then return the array sorted. Testing with a different array', () => {
const file = rewire("./app.js");
const sortNames = file.__get__('sortNames');
let names = ['John', 'Kenny', 'Tom', "Bob", 'Dilan'];
let sortedNames = ['Bob', 'Dilan', 'John', 'Kenny', 'Tom'];
expect(sortNames(names)).toEqual(sortedNames);
});