atecarlos / protractor-http-mock

A library designed to work alongside Protractor for setting up mocks for your HTTP ajax requests.
MIT License
173 stars 70 forks source link

Support expectations/assetions about requests. #9

Closed nielssj closed 9 years ago

nielssj commented 9 years ago

The way I see it a frontend has two input/output interfaces. First one being user triggered events and form-input on the DOM and the application's response in the form of modifications to the DOM. The second being HTTP requests/responses between the frontend and backend. Due to this I keep coming up with test cases that cannot be fully asserted without inspecting requests made to the backend.

I sketched out a working example of how this can be accomplished. I'm a newbie to the guts of Angular, so it's quite possible that there are better ways to publish and retrieve the list of requests from httpMock module.

I didn't include an example spec but since WebDriver.executeAsyncScript returns a promise your tests can basically do expectations like this:

    expect(requestsMade()).toEqual([
        { url : 'http://localhost:2121/user', method : 'GET' }
    ]);

This is tested and works like a charm in my specs.

atecarlos commented 9 years ago

Hi @nielssj ! Thanks for the PR. Could you please attach an example of a spec were you are using this functionality?

nielssj commented 9 years ago

Here is an example spec. However, I would suggest to expand the example application slightly, adding a few input fields and handler to make a POST request. This will showcase the value of the feature much better, as the request will contain actual POST data collected by the application from the input fields.

I'd be happy to add this, if you agree.

atecarlos commented 9 years ago

Hi @nielssj . I completely agree. I just pushed an example with POST to the repository. Thank you so much for adding the example. I will go ahead and merge your PR. Thanks!