Skip to content

Commit aa661a2

Browse files
committed
Add tests for negative cases
1 parent 7794e38 commit aa661a2

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

__tests__/page-loader.test.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,30 @@ test('page-loader', async () => {
5959
expect(downloadedScript).toBe('js {}')
6060
})
6161

62-
test('page-loader no such directory', async () => {
62+
test('page-loader: network errors', async () => {
6363
nock('https://ru.hexlet.io')
6464
.get('/courses')
65+
.reply(404)
66+
nock('https://ru.hexlet.io')
67+
.get('/assets/professions/nodejs.png')
68+
.reply(500)
69+
70+
await expect(downloadPage('https://ru.hexlet.io/courses', tempDir))
71+
.rejects
72+
.toThrow('Cant get https://ru.hexlet.io/courses - Request failed with status code 404')
73+
await expect(downloadPage('https://ru.hexlet.io/assets/professions/nodejs.png', tempDir))
74+
.rejects
75+
.toThrow('Cant get https://ru.hexlet.io/assets/professions/nodejs.png - Request failed with status code 500')
76+
})
77+
78+
test('page-loader: file operation errors', async () => {
79+
nock('https://ru.hexlet.io')
80+
.get('/courses')
81+
.times(2)
6582
.reply(200, html)
6683

67-
await expect(downloadPage('https://ru.hexlet.io/courses', 'unexistingDir'))
68-
.rejects.toThrow()
84+
await expect(downloadPage('https://ru.hexlet.io/courses', '/unexisting'))
85+
.rejects.toThrow('ERROR: No such output directory - /unexisting')
86+
await expect(downloadPage('https://ru.hexlet.io/courses', '/root'))
87+
.rejects.toThrow('ERROR: No access to output directory - /root')
6988
})

0 commit comments

Comments
 (0)