title: Testing Service. TypeError: done.fail is not a function
body: <p>I have tried this test, for testing my service:</p>
  
  <p>It has shown this error: </p>
  
  <pre><code>TypeError: done.fail is not a function
  </code></pre>
  
  <p>test file</p>
  
  <pre><code> it('should return reasonable json ssss', inject([ProductService, MockBackend], async((service: ProductService, mockBackend: MockBackend) =&gt; {
         const mockResponse = {
              data: [
                  { id: 0, details: 'All cats are lions' },
                  { id: 1, details: 'Video 1' },
                  { id: 2, details: 'Video 2' },
                  { id: 3, details: 'Video 3' },
              ]
          };
          mockBackend.connections.subscribe(connection =&gt; {
              connection.mockRespond(new Response(
                  new ResponseOptions({
                      body: [
                          { id: 0, details: 'All cats are lions' },
                          { id: 1, details: 'Video 1' },
                          { id: 2, details: 'Video 2' },
                          { id: 3, details: 'Video 3' },
                      ]
                  })));
          });
          service.productsgetall().subscribe((facts) =&gt; {
              console.log(facts)
              expect(facts[0].details).toEqual('ffff');
          });
      })));
  </code></pre>
  
  <p>-
      My service.ts</p>
  
  <pre><code>public productsgetall(): Observable&lt;Products[]&gt; {
                  ...
   return this.http.get(Api.getUrl(Api.URLS.productsgetall), {
        headers: headers
      }).map((response: Response) =&gt; {
          let res = response.json();
          if (res.StatusCode === 1) {
            this.auth.logout();
          } else {
            return res.StatusDescription.map(aa =&gt; {
              return new Products(aa);
            });
          }
    });
  }
  </code></pre>
  
  <p>Can you tell me what is the problem in my code and how to write good testing? If this testing is not good, please suggest something.</p>
  
  <p>Thanks.</p>
  
  <p>Edit, my final code. The error: </p>
  
  <blockquote>
    <p>TypeError: done.fail is not a function</p>
  </blockquote>
  
  <pre><code>it('should return reasonable json ssss', (done) =&gt; {
      inject([ProductService, MockBackend], async((service: ProductService, mockBackend: MockBackend) =&gt; {
  
          const mockResponse = {
              data: [
                  { alarmnumber: 0, alarmdesc: 'All cats are lions' },
                  { alarmnumber: 1, alarmdesc: 'Video 1' },
                  { alarmnumber: 2, alarmdesc: 'Video 2' },
                  { alarmnumber: 3, alarmdesc: 'Video 3' },
              ]
          };
  
          mockBackend.connections.subscribe(connection =&gt; {
              connection.mockRespond(new Response(
                  new ResponseOptions({
                      body: [
                          { alarmnumber: 0, alarmdesc: 'All cats are lions' },
                          { alarmnumber: 1, alarmdesc: 'Video 1' },
                          { alarmnumber: 2, alarmdesc: 'Video 2' },
                          { alarmnumber: 3, alarmdesc: 'Video 3' },
                      ]
                  })));
          });
  
          service.productsgetall().subscribe(facts=&gt; {
              console.log(facts);
              console.log(facts[0]);
             // expect(facts.length).toEqual(300);
              expect(facts[0].alarmdesc).toEqual('ffff');
              done();
          },
          (error) =&gt; done.fail());
      }))();
  });
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/i69WZ.png" rel="nofollow noreferrer">image error</a></p>