-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.test.js
47 lines (38 loc) · 1.26 KB
/
index.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* eslint-env jest */
const fs = require('fs')
const nock = require('nock')
const parser = require('./')
describe('rss-url-parser', () => {
test('rejects when an error occurs during the request', async () => {
nock('https://foo.com')
.get('/')
.replyWithError({ message: 'something awful happened' })
await expect(parser('https://foo.com')).rejects.toThrow()
})
test('rejects when a non-200 status code is received', async () => {
nock('https://foo.com')
.get('/')
.reply(404)
await expect(parser('https://foo.com')).rejects.toEqual(new Error(
'Bad status code: 404'
))
})
test('rejects if the response is not valid XML', async () => {
nock('https://foo.com')
.get('/')
.reply(200, '<h1>Some html</h1>')
await expect(parser('https://foo.com')).rejects.toEqual(new Error(
'Not a feed'
))
})
test('resolves if the response is expected', async () => {
const stubData = fs.readFileSync('./stub-data/feed.xml', 'utf-8')
nock('https://foo.com')
.get('/')
.reply(200, stubData)
const expected = expect.arrayContaining([expect.objectContaining({
author: expect.any(String)
})])
await expect(parser('https://foo.com')).resolves.toEqual(expected)
})
})