Add tests to verify behavior

This commit is contained in:
Paul Betts 2015-11-25 15:20:50 -08:00
parent 7cce3987eb
commit 15b8d7680e

View file

@ -81,6 +81,21 @@ describe 'protocol module', ->
error: (xhr, errorType, error) ->
done(error)
it 'sets Access-Control-Allow-Origin', (done) ->
handler = (request, callback) -> callback(text)
protocol.registerStringProtocol protocolName, handler, (error) ->
return done(error) if error
$.ajax
url: "#{protocolName}://fake-host"
success: (data, status, request) ->
assert.equal data, text
assert.equal(
request.getResponseHeader('Access-Control-Allow-Origin'),
'*')
done()
error: (xhr, errorType, error) ->
done(error)
it 'sends object as response', (done) ->
handler = (request, callback) -> callback(data: text, mimeType: 'text/html')
protocol.registerStringProtocol protocolName, handler, (error) ->
@ -120,6 +135,21 @@ describe 'protocol module', ->
error: (xhr, errorType, error) ->
done(error)
it 'sets Access-Control-Allow-Origin', (done) ->
handler = (request, callback) -> callback(buffer)
protocol.registerBufferProtocol protocolName, handler, (error) ->
return done(error) if error
$.ajax
url: "#{protocolName}://fake-host"
success: (data, status, request) ->
assert.equal data, text
assert.equal(
request.getResponseHeader('Access-Control-Allow-Origin'),
'*')
done()
error: (xhr, errorType, error) ->
done(error)
it 'sends object as response', (done) ->
handler = (request, callback) -> callback(data: buffer, mimeType: 'text/html')
protocol.registerBufferProtocol protocolName, handler, (error) ->
@ -163,6 +193,21 @@ describe 'protocol module', ->
error: (xhr, errorType, error) ->
done(error)
it 'sets Access-Control-Allow-Origin', (done) ->
handler = (request, callback) -> callback(filePath)
protocol.registerFileProtocol protocolName, handler, (error) ->
return done(error) if error
$.ajax
url: "#{protocolName}://fake-host"
success: (data, status, request) ->
assert.equal data, String(fileContent)
assert.equal(
request.getResponseHeader('Access-Control-Allow-Origin'),
'*')
done()
error: (xhr, errorType, error) ->
done(error)
it 'sends object as response', (done) ->
handler = (request, callback) -> callback(path: filePath)
protocol.registerFileProtocol protocolName, handler, (error) ->