Tree55Topz
Tree55Topz

Reputation: 1142

Mocking APIs for angular app component testing

Currently my team and I are facing an issue with our testing strategy.. We have our mocks set up in a completely inefficient way and need to find a better solution. Currently what we do is create a JSON file, often copied from the network traffic on the UI, and then in our component test we just use httpBackend and do a whenGET(jsonFileIWasTalkingAbout).

This is proving to be inefficient because we have to create a new JSON file, even if it is for the same API, to fit the test data needs of that component test.

What we are looking for is a more reusable solution, where we can pass in data to feed the API mock rather than what we are currently doing. Does anyone have a good mocking solution in place that they would like to brag about or any tools they have found that have worked? Any help would be much appreciated. Thanks!

Upvotes: 1

Views: 165

Answers (1)

alpeshpandya
alpeshpandya

Reputation: 492

I think combination of stub and Fake XMLHTTPRequest from SinonJS should help you achieve what you need.

Upvotes: 0

Related Questions