2

on back-end i use Spring Boot, on front-end i use Angular 2. i write simple tests for my front-end, but i want to mock my back-end. i search in google but i do not found answer for my question. how to mock back-end on testing with protractor? sorry for my english! thanks!

i tried this: https://www.npmjs.com/package/protractor-mock-backend# but then i found this: https://github.com/angular/protractor/blob/582411b7ad6c0f9176b231dc51dc328b98affbdf/lib/protractor.js#L717

  • if your backend is via REST, then you could use a simple [json-server](https://github.com/typicode/json-server) - this is very basic and can be started prior to e2e (e.g. in protractor's `beforeLaunch` callback) – Ovidiu Dolha May 30 '17 at 10:21
  • thanks, it's work for me! – Igor Turcanu May 30 '17 at 13:10

2 Answers2

3

If your backend is via REST, then you could use a simple json-server - this is very basic and can be started prior to e2e (e.g. in protractor's beforeLaunch callback)

(added from comment since it seemed to be a useful answer)

Ovidiu Dolha
  • 5,335
  • 1
  • 21
  • 30
  • An example auto-starting and auto-stopping mocks with node express during e2e tests: https://stackoverflow.com/a/45638832/786389 – Josh Hibschman Aug 11 '17 at 15:39
0

The best way to mock you API's with an Angular 2 app is with ng-Apimock. As far as I know the only plugin on the market now that can support local development as well as E2E-testing.

I'm using it in a Angular 2 app for a customer and it works like a charm. There are enough doccs / plugins to get it working with for example grunt, gulp, Anguler-CLI, Angular-seed and so on.

Hope it helps you

wswebcreation
  • 2,365
  • 2
  • 10
  • 18