blog.base2.io

We are Base Two, a technology company in Columbus, OH.

October 29, 2013 – Zack Brown Conditionally Mock $httpBackend

I recently followed this awesome blog post to mock $httpBackend for my end-to-end tests. The problem I immediately ran into is that, while mock data is fine for my e2e tests, I want to connect to a local backend when developing and get real data.

Conditionally inject e2e-mocks

The Burnside Digital blog post suggests including the following script in your application’s index.html.

Karma’s end-to-end tests open your application in an iFrame. To conditionally inject the mocked $httpBackend, we can check to see if we are in an iFrame and only include e2e-mocks if we are.

Now, when developing, you can work with your development server and when testing you can use mocked data.

blog comments powered by Disqus