“Mock” a backend http response with Protractor, Cucumber and Chai

本小妞迷上赌 提交于 2019-12-06 07:33:36

问题


First of all i will explain my goal : I have an app divided into several modules. In this case I just want to test my ui-module. I have some calls to the back-end there and i want to simulate the response or just change some models' values. I think you can not change the value of a model, so i am trying to simulate the back-end.

I have a model 'documents' that when i press a search button, it get data from the back-end in other module. Example: http://localhost:8080/search-module/API/search I want to test that without the backend.

I have tried with "httpbackend" but i can not get it going. Also i have tried "protractor-http-mock" and neither

Here is all my code for now:

I am starting with cucumber and mocking so forgive me if this question is so general.


回答1:


Here is the final solution for this. After 2 days of research I have everything working. https://docs.google.com/document/d/1beEchJyQejSLajJo1zqOd0gdUtaAESIqIkBXPzOs_IU/edit?usp=sharing

After try to test something with this "framework". I can say chai is not necessary. Just with Protractor-cucumber-framework and cucumber package is enough




回答2:


I've seen Pinch Hitter and WebMock used for that in ruby.

If you want an out-of-process server, I have a simulator that will let you POST the next GET if that helps.

Scenario Outline: Request a special service reply for a particular path
  When I request a GET for "<response>" from "<path>"
  And I send a GET to "<path>"
  Then I receive "<response>"
Examples:
  | path   | response                        |
  | /test1 | col1,col1\nr1c1,r1c2\nr2c1,r2c2 |

@service.get
Scenario Outline: Request a service reply from a preset file
  When I have a file "<name>" with "<contents>"
  And I send a GET to "<name>"
  Then I receive "<contents>"
Examples:
  | name | contents                                |
  | temp | One fish, two fish, red fish, blue fish |


来源:https://stackoverflow.com/questions/37432597/mock-a-backend-http-response-with-protractor-cucumber-and-chai

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!