Skip to content

Instantly share code, notes, and snippets.

@AhsanAyaz
Created July 19, 2023 07:58
Show Gist options
  • Save AhsanAyaz/9d6d4daf743c13305f396458e48f3155 to your computer and use it in GitHub Desktop.
Save AhsanAyaz/9d6d4daf743c13305f396458e48f3155 to your computer and use it in GitHub Desktop.
Snippet for ng-test-http-resp including mock users
it('should return expected user data (HttpClient called once)', () => {
const mockUsers: User[] = [
{
id: 1,
name: 'User A',
email: 'userA@example.com',
username: 'userA',
address: {
street: 'sample street 1',
suite: '123 ABC',
city: 'Dream city',
zipcode: '4567'
}
},
{
id: 2,
name: 'User B',
email: 'userA@example.com',
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