Created
July 19, 2023 07:58
-
-
Save AhsanAyaz/9d6d4daf743c13305f396458e48f3155 to your computer and use it in GitHub Desktop.
Snippet for ng-test-http-resp including mock users
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('should return expected user data (HttpClient called once)', () => { | |
const mockUsers: User[] = [ | |
{ | |
id: 1, | |
name: 'User A', | |
email: '[email protected]', | |
username: 'userA', | |
address: { | |
street: 'sample street 1', | |
suite: '123 ABC', | |
city: 'Dream city', | |
zipcode: '4567' | |
} | |
}, | |
{ | |
id: 2, | |
name: 'User B', | |
email: '[email protected]', | |
username: 'userA', | |
address: { | |
street: 'sample street 2', | |
suite: '123 ABC', | |
city: 'Dream city', | |
zipcode: '890' | |
} | |
}, | |
]; | |
const req = httpTestingController.expectOne('assets/users.json'); | |
expect(req.request.method).toEqual('GET'); | |
req.flush(mockUsers); // Respond with mocked data | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment