Skip to content

Commit 2cb6b91

Browse files
committed
Add test to expect failure handling
1 parent 4ee7c3a commit 2cb6b91

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

test/karma.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
function reply(request, response, next) {
22
if (request.method === 'GET') {
3-
response.writeHead(200)
3+
const status = request.url.startsWith('/500') ? 500 : 200
4+
response.writeHead(status)
5+
response.ok = status === 200
46
response.end(`
57
<ol data-src="${request.url}">
68
<li>item</li>

test/test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@ describe('remote-input', function() {
3838
input.focus()
3939
})
4040

41+
it('handles not ok responses', function(done) {
42+
const remoteInput = document.querySelector('remote-input')
43+
const input = document.querySelector('input')
44+
const results = document.querySelector('#results')
45+
remoteInput.src = '/500'
46+
assert.equal(results.innerHTML, '')
47+
let errorHappened = false
48+
remoteInput.addEventListener('error', function() {
49+
errorHappened = true
50+
})
51+
remoteInput.addEventListener('loadend', function() {
52+
assert.ok(errorHappened, 'error event happened')
53+
assert.equal(results.innerHTML, '', 'nothing was appended')
54+
done()
55+
})
56+
input.value = 'test'
57+
input.focus()
58+
})
59+
4160
it('repects param attribute', function(done) {
4261
const remoteInput = document.querySelector('remote-input')
4362
const input = document.querySelector('input')

0 commit comments

Comments
 (0)