Using ngMock for backend-less testing an external

2019-09-15 04:28发布

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.

1条回答
贼婆χ
2楼-- · 2019-09-15 05:02

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.

查看更多
登录 后发表回答