diff --git a/spec/api-protocol-spec.js b/spec/api-protocol-spec.js index bee5886e64..12590c195c 100644 --- a/spec/api-protocol-spec.js +++ b/spec/api-protocol-spec.js @@ -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') }) }) diff --git a/spec/fixtures/pages/jquery.html b/spec/fixtures/pages/jquery.html index 162a885f94..45c33a63cf 100644 --- a/spec/fixtures/pages/jquery.html +++ b/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) })