Browse Source

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

* fix protocol 404 fake tests

* fix another fake test

* fix last fake test (hopefully)
Micha Hanselmann 5 years ago
parent
commit
504edf2cf6
2 changed files with 11 additions and 10 deletions
  1. 10 9
      spec/api-protocol-spec.js
  2. 1 1
      spec/fixtures/pages/jquery.html

+ 10 - 9
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')
     })
   })
 

+ 1 - 1
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)
     })