-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtorro.test.js
29 lines (24 loc) · 883 Bytes
/
torro.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
const fetchArticle = require('./torro');
const searchUrl = 'http://localhost:8080/articles/search/';
const fetch = require('node-fetch');
it('fetchArticle logic OK', () => {
const fakeFetch = jest.fn().mockReturnValue(Promise.resolve({
json: () => Promise.resolve({
data:
[ { id: 2,
content: 'Review code',
status: 1,
created_at: '2016-04-10T20:50:40.000Z' },
{ id: 4,
content: 'RefActor Code',
status: 1,
created_at: '2016-04-10T20:50:40.000Z' } ],
message: 'Articles search list.' })
}))
return fetchArticle(fakeFetch, searchUrl, 'code')
.then(res => res.map((el) => expect(el.content).toMatch(/ode/)))
})
it('API works correctly', () => {
return fetchArticle(fetch, searchUrl, 'Intel')
.then(res => res.map((el) => expect(el._search.content).toMatch(/ntel/)))
})