Skip to content

Commit da246d0

Browse files
Add testing case for gitRepo
1 parent f6b0ab6 commit da246d0

File tree

4 files changed

+12
-30
lines changed

4 files changed

+12
-30
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ node_modules
55
package-lock.json
66
*tempCodeRunnerFile.js
77
/coverage
8+
OOP.js
89
#
910
# Optional npm cache directory
1011
.npm

operations/git_api/getRepo.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const fetch = require("node-fetch")
12
//Takes a username as an argument and makes a call to GitHub API
23
//and returns all the repositoriesowned by the user as an array.
34

@@ -8,7 +9,7 @@ async function showGitHubRepos(handle) {
89

910
return repos.map(repo => repo.name);
1011
}
11-
//showGitHubRepos("whiteh").then(data => console.log(data));
12+
showGitHubRepos("whiteh").then(data => console.log(data));
1213

1314
const myrepo = [
1415
"Ball-Bouncing-and-Collision",

operations/git_api/getRepo.test.js

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,15 @@
1-
let showGitHubRepos = require("./getRepo")
21

3-
describe("Mock testing showGitHubRepos implementation", () => {
4-
it("Test user with repositories", async () => {
5-
showGitHubRepos = jest
6-
.fn()
7-
.mockResolvedValue([
8-
"Ball-Bouncing-and-Collision",
9-
"css-grid",
10-
"CSS-Grid-Calculator",
11-
"CSS-Grid-Phone",
12-
"css-protips",
13-
"Databaseless-API"
14-
]);
152

16-
let repos = await showGitHubRepos().then(data => data);
173

18-
expect(showGitHubRepos).toHaveBeenCalled();
4+
describe("Mock testing getRepo implementation", () => {
5+
it("Make sure fetchRepo function is called", async () => {
6+
let repos = await showGitHubRepos("iKnowJavaScript");
7+
198
expect(repos).toContain("CSS-Grid-Phone");
209
});
2110
it("Should return 'User has not repository yet' if it return an empty array", async () => {
22-
showGitHubRepos = jest.fn().mockResolvedValue([]);
23-
24-
let repos = await showGitHubRepos().then(data => data);
11+
let repos = await showGitHubRepos("rasaki");
2512

26-
expect(showGitHubRepos).toHaveBeenCalled();
2713
expect(repos).toEqual([]);
2814
});
29-
// it("Should return 'User not found' if no array was returned", async () => {
30-
// showGitHubRepos = jest.fn().mockRejectedValue(new Error("User Not Found"));
31-
32-
// const error = await showGitHubRepos();
33-
34-
// expect(showGitHubRepos).toHaveBeenCalled();
35-
// expect(error).toMatch(/Not Found/);
36-
// });
37-
});
38-
15+
});

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
"homepage": "https://github.com/iKnowJavaScript/tdd-with-jest#readme",
2020
"devDependencies": {
2121
"jest": "^24.7.1"
22+
},
23+
"dependencies": {
24+
"nodemon": "^1.18.11"
2225
}
2326
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy