2 Comments

  1. Peter

    Awesome! 🙂

    …but what about that version:

    it(‘should call the api’, async () => {
    const expected = { name: ‘Wiggles’, age: 25 };
    const response = await service.Get().toPromise();

    httpMock.expectOne(‘api/getstuff’).flush(expected);

    const result = await response;

    expect(result.name).toBe(‘Wiggles’);
    expect(result.age).toBe(25);

    httpMock.verify();
    });

    Btw. in expect(result.name).toBe('Wiggles'); you should always hard-coded expected value.

    • Hey Peter,

      Yeah, that test looks legit to me! I’m not sure I agree with always using hard-coded expected values — I tend to typo a lot, so I like to make constants at the beginning of a test to outline the expected values, just in case I need to type them more than once. I’ve blogged a lot about not liking magic strings, so having hard-coded values in the expect seems magic string-y to me.

Leave a Reply

Your email address will not be published. Required fields are marked *