Add tests to verify behavior
This commit is contained in:
parent
7cce3987eb
commit
15b8d7680e
1 changed files with 45 additions and 0 deletions
|
@ -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) ->
|
||||
|
|
Loading…
Reference in a new issue