Skip to content

Commit 3f318ce

Browse files
author
jfusco
committed
Finish ajax request/response unit test
1 parent 3fdb301 commit 3f318ce

6 files changed

Lines changed: 69 additions & 61 deletions

File tree

__tests__/Github-test.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { GitHub } from '../src/js/modules/Github'
77

88
jasmine.getFixtures().fixturesPath = 'base/src/modules'
99

10-
describe('Github.js', () => {
10+
describe('Github.js - instantiation', () => {
1111
let github = null
1212

1313
beforeEach(() => {
@@ -63,27 +63,38 @@ describe('Github.js', () => {
6363
})
6464
})
6565

66-
describe('Github - render', () => {
67-
beforeEach(() => {
68-
loadFixtures('github.html')
66+
describe('Github.js - ajax', () => {
67+
const github = new GitHub('DennisMartinez')
6968

70-
jasmine.Ajax.install();
71-
})
69+
let request
70+
71+
beforeEach(done => {
72+
jasmine.Ajax.install()
73+
74+
github.getUserData()
75+
76+
request = jasmine.Ajax.requests.mostRecent()
77+
request.respondWith(GithubResponse)
78+
79+
done()
80+
});
7281

7382
afterEach(() => {
7483
jasmine.Ajax.uninstall();
7584
})
7685

77-
it('should make a call to get user info', () => {
78-
const github = new GitHub('DennisMartinez')
86+
it('sends the request to the right end point', () => {
87+
expect(request.url).toBe('https://api.github.com/users/DennisMartinez')
88+
});
7989

80-
const spy = spyOn($, 'getJSON')
90+
it('uses the correct method', () => {
91+
expect(request.method).toBe('GET')
92+
});
8193

82-
jasmine.Ajax.stubRequest(`https://api.github.com/users/${github.username}`)
83-
.andReturn(GithubResponse)
84-
85-
github.getUserData()
94+
it('should return the correct data', () => {
95+
const data = JSON.parse(request.responseText)
8696

87-
expect(spy).toHaveBeenCalled()
97+
expect(typeof data).toBe('object')
98+
expect(data.name).toBe('Dennis Martinez')
8899
})
89100
})
Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
11
export default {
2-
users: {
3-
status: 200,
4-
contentType: 'application/json',
5-
responseText: {
6-
avatar_url: "https://avatars1.githubusercontent.com/u/1375616?v=3",
7-
bio: "mek a d weeb fun",
8-
blog: null,
9-
company: "Verndale",
10-
created_at: "2012-01-24T16:19:15Z",
11-
email: "denniswaltermartinez@gmail.com",
12-
events_url: "https://api.github.com/users/DennisMartinez/events{/privacy}",
13-
followers: 13,
14-
followers_url: "https://api.github.com/users/DennisMartinez/followers",
15-
following: 15,
16-
following_url: "https://api.github.com/users/DennisMartinez/following{/other_user}",
17-
gists_url: "https://api.github.com/users/DennisMartinez/gists{/gist_id}",
18-
gravatar_id: "",
19-
hireable: true,
20-
html_url: "https://github.com/DennisMartinez",
21-
id: 1375616,
22-
location: "CO",
23-
login: "DennisMartinez",
24-
name: "Dennis Martinez",
25-
organizations_url: "https://api.github.com/users/DennisMartinez/orgs",
26-
public_gists: 20,
27-
public_repos: 10,
28-
received_events_url: "https://api.github.com/users/DennisMartinez/received_events",
29-
repos_url: "https://api.github.com/users/DennisMartinez/repos",
30-
site_admin: false,
31-
starred_url: "https://api.github.com/users/DennisMartinez/starred{/owner}{/repo}",
32-
subscriptions_url: "https://api.github.com/users/DennisMartinez/subscriptions",
33-
type: "User",
34-
updated_at: "2017-03-25T16:42:02Z",
35-
url: "https://api.github.com/users/DennisMartinez"
36-
}
37-
}
2+
status: 200,
3+
responseText: JSON.stringify({
4+
avatar_url: "https://avatars1.githubusercontent.com/u/1375616?v=3",
5+
bio: "mek a d weeb fun",
6+
blog: null,
7+
company: "Verndale",
8+
created_at: "2012-01-24T16:19:15Z",
9+
email: "denniswaltermartinez@gmail.com",
10+
events_url: "https://api.github.com/users/DennisMartinez/events{/privacy}",
11+
followers: 13,
12+
followers_url: "https://api.github.com/users/DennisMartinez/followers",
13+
following: 15,
14+
following_url: "https://api.github.com/users/DennisMartinez/following{/other_user}",
15+
gists_url: "https://api.github.com/users/DennisMartinez/gists{/gist_id}",
16+
gravatar_id: "",
17+
hireable: true,
18+
html_url: "https://github.com/DennisMartinez",
19+
id: 1375616,
20+
location: "CO",
21+
login: "DennisMartinez",
22+
name: "Dennis Martinez",
23+
organizations_url: "https://api.github.com/users/DennisMartinez/orgs",
24+
public_gists: 20,
25+
public_repos: 10,
26+
received_events_url: "https://api.github.com/users/DennisMartinez/received_events",
27+
repos_url: "https://api.github.com/users/DennisMartinez/repos",
28+
site_admin: false,
29+
starred_url: "https://api.github.com/users/DennisMartinez/starred{/owner}{/repo}",
30+
subscriptions_url: "https://api.github.com/users/DennisMartinez/subscriptions",
31+
type: "User",
32+
updated_at: "2017-03-25T16:42:02Z",
33+
url: "https://api.github.com/users/DennisMartinez"
34+
})
3835
}

coverage/reports/lcov-report/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ <h1>
8181
</div><!-- /wrapper -->
8282
<div class='footer quiet pad2 space-top1 center small'>
8383
Code coverage
84-
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sat Apr 01 2017 23:16:12 GMT-0400 (EDT)
84+
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sun Apr 02 2017 10:51:55 GMT-0400 (EDT)
8585
</div>
8686
</div>
8787
<script src="prettify.js"></script>

coverage/reports/lcov-report/modules/Github.js.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ <h1>
215215
</div><!-- /wrapper -->
216216
<div class='footer quiet pad2 space-top1 center small'>
217217
Code coverage
218-
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sat Apr 01 2017 23:16:12 GMT-0400 (EDT)
218+
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sun Apr 02 2017 10:51:55 GMT-0400 (EDT)
219219
</div>
220220
</div>
221221
<script src="../prettify.js"></script>

coverage/reports/lcov-report/modules/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ <h1>
8181
</div><!-- /wrapper -->
8282
<div class='footer quiet pad2 space-top1 center small'>
8383
Code coverage
84-
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sat Apr 01 2017 23:16:12 GMT-0400 (EDT)
84+
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sun Apr 02 2017 10:51:55 GMT-0400 (EDT)
8585
</div>
8686
</div>
8787
<script src="../prettify.js"></script>

coverage/reports/lcov.info

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ FNDA:1,defineProperties
2525
FNDA:1,(anonymous_3)
2626
FNDA:2,_interopRequireDefault
2727
FNDA:1,_asyncToGenerator
28-
FNDA:1,(anonymous_6)
29-
FNDA:1,(anonymous_7)
30-
FNDA:1,step
28+
FNDA:4,(anonymous_6)
29+
FNDA:4,(anonymous_7)
30+
FNDA:4,step
3131
FNDA:0,(anonymous_9)
3232
FNDA:0,(anonymous_10)
3333
FNDA:7,_classCallCheck
3434
FNDA:1,(anonymous_12)
3535
FNDA:7,GitHub
3636
FNDA:1,(anonymous_14)
37-
FNDA:1,_callee
38-
FNDA:1,_callee$
39-
FNDA:1,getUserData
37+
FNDA:4,_callee
38+
FNDA:4,_callee$
39+
FNDA:4,getUserData
4040
FNDA:0,render
4141
DA:0,7
4242
DA:7,1
@@ -66,14 +66,14 @@ BRDA:24,5,1,2
6666
BRDA:24,6,0,2
6767
BRDA:24,6,1,2
6868
BRDA:26,7,0,0
69-
BRDA:26,7,1,1
69+
BRDA:26,7,1,4
7070
BRDA:28,8,0,0
7171
BRDA:28,8,1,7
7272
BRDA:34,9,0,2
7373
BRDA:34,9,1,5
7474
BRDA:34,10,0,7
7575
BRDA:34,10,1,6
76-
BRDA:48,11,0,1
76+
BRDA:48,11,0,4
7777
BRDA:48,11,1,0
7878
BRDA:48,11,2,0
7979
BRDA:48,11,3,0

0 commit comments

Comments
 (0)