Jessy Houle
Jessy Houle

Reputation: 1921

Using ngMock for backend-less testing an external site

Is there a way to use angular-mocks.js to invoke backend-less request mocking, testing an external site? There are plenty of examples using angular mocks on a codebase that the developer has access to add a . However, I'm stuck in a scenario... calling out to an Angular site, in the wild, which I need to test the frontend functionality, with well-known endpoints/results.

A quick fake example:

  1. Call out to www.externalwebsite.com/RealAngularApp
  2. RealAngularApp calls an endpoint www.externalwebsite.com/api/v1/getdata that returns { id: 1, name: "testing" }
  3. I need to intercept this (as angular mocks does), but without the ability to add the angular mocks script tag in the code (because it's an external site)

Any/all thoughts are welcome.

Thank you.

Upvotes: 0

Views: 163

Answers (1)

finspin
finspin

Reputation: 4071

You could use the https://github.com/atecarlos/protractor-http-mock library which lets you intercept HTTP requests and serve predefined responses. Great thing about this library is that you don't have to modify your application code.

Upvotes: 2

Related Questions