test: correct fake tests in api-protocol-spec (#18869)

* fix protocol 404 fake tests

* fix another fake test

* fix last fake test (hopefully)
This commit is contained in:
Micha Hanselmann 2019-06-19 13:40:49 -07:00 коммит произвёл Shelley Vohr
Родитель 0146cc0eb5
Коммит 504edf2cf6
2 изменённых файлов: 11 добавлений и 10 удалений

Просмотреть файл

@ -112,7 +112,7 @@ describe('protocol module', () => {
it('sends error when callback is called with nothing', async () => {
await registerBufferProtocol(protocolName, emptyHandler)
await expect(ajax(protocolName + '://fake-host')).to.be.eventually.rejectedWith(404)
await expect(ajax(protocolName + '://fake-host')).to.be.eventually.rejectedWith(Error, '404')
})
it('does not crash when callback is called in next tick', async () => {
@ -160,9 +160,10 @@ describe('protocol module', () => {
})
it('fails when sending object other than string', async () => {
const handler = (request, callback) => callback(new Date())
const notAString = () => {}
const handler = (request, callback) => callback(notAString)
await registerStringProtocol(protocolName, handler)
expect(ajax(protocolName + '://fake-host')).to.be.eventually.rejectedWith(Error)
await expect(ajax(protocolName + '://fake-host')).to.be.eventually.rejectedWith(Error, '404')
})
})
@ -198,7 +199,7 @@ describe('protocol module', () => {
it('fails when sending string', async () => {
const handler = (request, callback) => callback(text)
await registerBufferProtocol(protocolName, handler)
expect(ajax(protocolName + '://fake-host')).to.be.eventually.rejectedWith(Error)
await expect(ajax(protocolName + '://fake-host')).to.be.eventually.rejectedWith(Error, '404')
})
})
@ -252,13 +253,13 @@ describe('protocol module', () => {
const fakeFilePath = path.join(fixtures, 'asar', 'a.asar', 'not-exist')
const handler = (request, callback) => callback(fakeFilePath)
await registerFileProtocol(protocolName, handler)
await expect(ajax(protocolName + '://fake-host')).to.be.eventually.rejectedWith(404)
await expect(ajax(protocolName + '://fake-host')).to.be.eventually.rejectedWith(Error, '404')
})
it('fails when sending unsupported content', async () => {
const handler = (request, callback) => callback(new Date())
await registerFileProtocol(protocolName, handler)
await expect(ajax(protocolName + '://fake-host')).to.be.eventually.rejectedWith(404)
await expect(ajax(protocolName + '://fake-host')).to.be.eventually.rejectedWith(Error, '404')
})
})
@ -282,13 +283,13 @@ describe('protocol module', () => {
it('fails when sending invalid url', async () => {
const handler = (request, callback) => callback({ url: 'url' })
await registerHttpProtocol(protocolName, handler)
await expect(ajax(protocolName + '://fake-host')).to.be.eventually.rejectedWith(404)
await expect(ajax(protocolName + '://fake-host')).to.be.eventually.rejectedWith(Error, '404')
})
it('fails when sending unsupported content', async () => {
const handler = (request, callback) => callback(new Date())
await registerHttpProtocol(protocolName, handler)
await expect(ajax(protocolName + '://fake-host')).to.be.eventually.rejectedWith(404)
await expect(ajax(protocolName + '://fake-host')).to.be.eventually.rejectedWith(Error, '404')
})
it('works when target URL redirects', async () => {
@ -478,7 +479,7 @@ describe('protocol module', () => {
it('sends error when callback is called with nothing', async () => {
await interceptStringProtocol('http', emptyHandler)
await expect(ajax('http://fake-host')).to.be.eventually.rejectedWith(404)
await expect(ajax('http://fake-host')).to.be.eventually.rejectedWith(Error, '404')
})
})

2
spec/fixtures/pages/jquery.html поставляемый
Просмотреть файл

@ -12,7 +12,7 @@
resolve({data, status: request.status, headers: request.getAllResponseHeaders()})
}
options.error = (xhr, errorType, error) => {
reject(error ? error : xhr.status)
reject(error ? error : new Error(`${xhr.status}`))
}
$.ajax(options)
})