dimanche 25 mars 2018

Integration tests in Angular application

I am a bit confused about thistest:

  describe('#getUsers', () => {
    it('should return an Observable<User[]>', () => {
      const dummyUsers: User[] = [
        new User(0, 'John'),
        new User(1, 'Doe')
      ];

      service.getUsers().subscribe(users => {
        expect(users.length).toBe(2);
        expect(users).toEqual(dummyUsers);
      });

      const req = httpMock.expectOne(`${service.API_URL}/users`);
      expect(req.request.method).toBe('GET');
      req.flush(dummyUsers);
    });
  });

I saw the similar examples many times, during learning about tests in the Angular applications.

If I see good, we are declaring an array of Users and then we are returning the same array in response of request.

Finally we are checking if the created array is the same as received. I cant understand the purpose, it looks really strange to me. What is the point of comparing the same array to the same array?

Shouldn't I make a real GET to the API and then check if there are elements in response?

Aucun commentaire:

Enregistrer un commentaire