Skip to content

Commit 11e3375

Browse files
author
Ushang Thakker
committed
Added: Component Tests
1 parent 09dc5c8 commit 11e3375

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

__tests__/Detail-test.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
jest.autoMockOff();
2+
3+
import React from 'react';
4+
import ReactDOM from 'react-dom';
5+
import TestUtils from 'react-addons-test-utils';
6+
7+
const Detail = require('../src/components/Detail/Detail').default;
8+
9+
describe('Detail', () => {
10+
// tests go here
11+
it('starts with zero commits', () => {
12+
const rendered = TestUtils.renderIntoDocument(
13+
<Detail params={{repo: ''}} />
14+
);
15+
16+
expect(rendered.state.commits.length).toEqual(0);
17+
});
18+
19+
it('shows commits by default', () => {
20+
const rendered = TestUtils.renderIntoDocument(
21+
<Detail params={{repo: ''}} />
22+
);
23+
24+
expect(rendered.state.mode).toEqual('commits');
25+
});
26+
27+
it('shows forks when the button is tapped', () => {
28+
const rendered = TestUtils.renderIntoDocument(
29+
<Detail params={{repo: ''}} />
30+
);
31+
32+
const btns = TestUtils.scryRenderedDOMComponentsWithTag(rendered, 'button');
33+
const forksButton = btns[1];
34+
TestUtils.Simulate.click(forksButton);
35+
expect(rendered.state.mode).toEqual('forks');
36+
});
37+
38+
it('fetches forks from Github', () => {
39+
const rendered = TestUtils.renderIntoDocument(
40+
<Detail params={{repo: 'react'}} />
41+
);
42+
43+
beforeEach(() => {
44+
if (rendered.state.forks.length > 0) {
45+
console.log('Waiting for forks: ' + rendered.state.forks.length);
46+
done();
47+
}
48+
}, "commits to be set", 2000);
49+
50+
afterEach(() => {
51+
expect(rendered.state.forks.length).toEqual(30);
52+
});
53+
});
54+
55+
});

__tests__/List-test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
jest.disableAutomock();
2+
3+
import React from 'react';
4+
import ReactDOM from 'react-dom';
5+
import TestUtils from 'react-addons-test-utils';
6+
7+
const List = require('../src/components/List/List').default;
8+
9+
describe('List', () => {
10+
it('renders three repo links', () => {
11+
const rendered = TestUtils.renderIntoDocument(
12+
<List />
13+
);
14+
15+
const repos = TestUtils.scryRenderedDOMComponentsWithTag(rendered, 'li');
16+
17+
expect(repos.length).toEqual(3);
18+
});
19+
});

0 commit comments

Comments
 (0)