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

Backend should be mocked just by matching URL and method, data and others optional #30

Closed RyanWarner closed 9 years ago

RyanWarner commented 9 years ago

When setting up my mocks, if my actual HTTP request includes data and I fail to include the data attribute in the mock request, the entire HTTP request is not intercepted.

mock( [
{
    request:
    {
      path: '/api/user/list',
      withCredentials: true,
      method: 'post',
    },
    ...
] };

This fails to intercept the request and I can see my backend being hit. However...

mock( [
{
    request:
    {
      path: '/api/user/list',
      withCredentials: true,
      method: 'post',
      data:
      {
        listItem:
        {
            name: 'new list item'
        }
    }
    },
    ...
] };

This WILL intercept the request. This was unexpected behavior to me, especially because leaving out `withCredentials` exhibits opposite behavior: the request is mocked.

Part of me feels like the HTTP request should get mocked simply by matching just the URL and method, and everything else is optional.

Regardless, this behavior should be consistent and documented.

Does this make sense?
atecarlos commented 9 years ago

Yes. I understand your problem, and yes that was the original behavior. I'll change it back and release soon. I will update here when ready.

atecarlos commented 9 years ago

Done! Just published new version 0.1.13 with the fix. Let me know how that works for you.