Skip to content

Commit 0969125

Browse files
committed
added jest.mock('axios'), so axios is mecked with fake responses
1 parent 392304d commit 0969125

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

sites/meo.pt/meo.pt.test.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ const customParseFormat = require('dayjs/plugin/customParseFormat')
77
dayjs.extend(customParseFormat)
88
dayjs.extend(utc)
99

10+
const axios = require('axios')
11+
12+
jest.mock('axios')
13+
1014
const date = dayjs.utc('2022-12-02', 'YYYY-MM-DD').startOf('d')
1115
const channel = {
1216
site_id: 'RTPM',
@@ -39,9 +43,13 @@ it('can generate valid request method', () => {
3943
})
4044
})
4145

42-
it('can parse response', () => {
46+
it('can parse response', async () => {
4347
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
44-
let results = parser({ content }).map(p => {
48+
49+
axios.post.mockResolvedValue({ data: {} })
50+
51+
let results = await parser({ content })
52+
results = results.map(p => {
4553
p.start = p.start.toJSON()
4654
p.stop = p.stop.toJSON()
4755
return p
@@ -54,7 +62,7 @@ it('can parse response', () => {
5462
})
5563
})
5664

57-
it('can handle empty guide', () => {
58-
const result = parser({ content: '', channel, date })
65+
it('can handle empty guide', async () => {
66+
const result = await parser({ content: '', channel, date })
5967
expect(result).toMatchObject([])
6068
})

0 commit comments

Comments
 (0)