Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 88e615f

Browse files
committed
Remove unused content type tests
1 parent 28cbd7b commit 88e615f

File tree

2 files changed

+15
-49
lines changed

2 files changed

+15
-49
lines changed

test/karma.config.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
function checker(request, response, next) {
2-
if (request.method === 'POST' && request.url.startsWith('/plaintext')) {
3-
response.writeHead(200)
4-
response.end('This is a warning')
5-
return
6-
} else if (request.method === 'POST' && request.url.startsWith('/fail')) {
7-
response.setHeader('Content-Type', 'application/json')
2+
if (request.method === 'POST' && request.url.startsWith('/fail')) {
83
response.writeHead(422)
9-
response.end('{"text": "This is a error"}')
4+
response.end('This is an error')
105
return
116
} else if (request.method === 'POST' && request.url.startsWith('/success')) {
12-
response.setHeader('Content-Type', 'application/json')
137
response.writeHead(200)
14-
response.end('{"text": "This is a warning"}')
8+
response.end('This is a warning')
159
return
1610
}
1711
next()

test/test.js

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -31,41 +31,35 @@ describe('auto-check element', function() {
3131
document.body.innerHTML = ''
3232
})
3333

34-
it('emits a send event on input', function(done) {
34+
it('emits send event on input', function(done) {
3535
const input = document.querySelector('auto-check input')
3636
input.addEventListener('auto-check-send', () => done())
3737
input.value = 'hub'
3838
input.dispatchEvent(new InputEvent('input'))
3939
})
4040

41-
it('emits a send event on change', function(done) {
41+
it('emits send event on change', function(done) {
4242
const input = document.querySelector('auto-check input')
4343
input.addEventListener('auto-check-send', () => done())
4444
triggerChange(input, 'hub')
4545
})
4646

47-
it('emits a success event when server returns a non error response', function(done) {
48-
const input = document.querySelector('auto-check input')
49-
input.addEventListener('auto-check-success', () => done())
50-
triggerChange(input, 'hub')
51-
})
52-
53-
it('emits a success event with message when server returns a non error response', async function() {
47+
it('emits success event when server responds with 200 OK', async function() {
5448
const input = document.querySelector('auto-check input')
5549
triggerChange(input, 'hub')
5650
const event = await once(input, 'auto-check-success')
5751
const result = await event.detail.response.text()
58-
assert.deepEqual('{"text": "This is a warning"}', result)
52+
assert.equal('This is a warning', result)
5953
})
6054

61-
it('emits a error event when server returns a error response', async function() {
55+
it('emits error event when server returns an error response', async function() {
6256
const autoCheck = document.querySelector('auto-check')
6357
const input = autoCheck.querySelector('input')
6458
autoCheck.src = '/fail'
6559
triggerChange(input, 'hub')
6660
const event = await once(input, 'auto-check-error')
6761
const result = await event.detail.response.text()
68-
assert.deepEqual('{"text": "This is a error"}', result)
62+
assert.equal('This is an error', result)
6963
})
7064

7165
it('customizes the error message', async function() {
@@ -102,13 +96,13 @@ describe('auto-check element', function() {
10296
assert.equal('Checking with server', input.validationMessage)
10397
})
10498

105-
it('sets input as invalid if input is required and not filled in', function() {
99+
it('sets required input as invalid when empty', function() {
106100
const checker = document.querySelector('auto-check')
107101
checker.required = true
108102
assert.isFalse(checker.querySelector('input').checkValidity())
109103
})
110104

111-
it('sets input as invalid while the check request is in-flight', async function() {
105+
it('sets required input as invalid while the request is in-flight', async function() {
112106
const checker = document.querySelector('auto-check')
113107
checker.required = true
114108
const input = checker.querySelector('input')
@@ -117,7 +111,7 @@ describe('auto-check element', function() {
117111
assert.isFalse(input.checkValidity())
118112
})
119113

120-
it('sets input as invalid if the check request comes back with a error', async function() {
114+
it('sets required input as invalid on failed server response', async function() {
121115
const autoCheck = document.querySelector('auto-check')
122116
autoCheck.required = true
123117
autoCheck.src = '/fail'
@@ -127,7 +121,7 @@ describe('auto-check element', function() {
127121
assert.isFalse(input.checkValidity())
128122
})
129123

130-
it('sets input as valid if the check request comes back with a success', async function() {
124+
it('sets required input as valid on successful server response', async function() {
131125
const autoCheck = document.querySelector('auto-check')
132126
autoCheck.required = true
133127
const input = autoCheck.querySelector('input')
@@ -147,13 +141,13 @@ describe('auto-check element', function() {
147141
assert.isTrue(input.checkValidity())
148142
})
149143

150-
it('emits a complete event at the end of the lifecycle', function(done) {
144+
it('emits complete event at the end of the lifecycle', function(done) {
151145
const input = document.querySelector('auto-check input')
152146
input.addEventListener('auto-check-complete', () => done())
153147
triggerChange(input, 'hub')
154148
})
155149

156-
it('emits a send event before checking if there is a duplicate request', function(done) {
150+
it('emits send event before checking if there is a duplicate request', function(done) {
157151
const input = document.querySelector('auto-check input')
158152

159153
let counter = 2
@@ -169,28 +163,6 @@ describe('auto-check element', function() {
169163
input.dispatchEvent(new InputEvent('change'))
170164
input.dispatchEvent(new InputEvent('change'))
171165
})
172-
173-
it('handles plain text responses', async function() {
174-
const autoCheck = document.querySelector('auto-check')
175-
const input = autoCheck.querySelector('input')
176-
autoCheck.src = '/plaintext'
177-
triggerChange(input, 'hub')
178-
const event = await once(input, 'auto-check-success')
179-
const result = await event.detail.response.text()
180-
assert.deepEqual('This is a warning', result)
181-
})
182-
183-
describe('`auto-check-error` event', async function() {
184-
it('includes `Content-Type` header in event payload', async function() {
185-
const autoCheck = document.querySelector('auto-check')
186-
const input = document.querySelector('input')
187-
autoCheck.src = '/fail'
188-
triggerChange(input, 'hub')
189-
const event = await once(input, 'auto-check-error')
190-
const contentType = event.detail.response.headers.get('Content-Type')
191-
assert.equal('application/json', contentType)
192-
})
193-
})
194166
})
195167
})
196168

0 commit comments

Comments
 (0)