New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no more partial matches for body #981

Closed
cristianszwarc opened this Issue Sep 25, 2017 · 6 comments

Comments

Projects
None yet
4 participants
@cristianszwarc

cristianszwarc commented Sep 25, 2017

previously you could specify part of the body to answer calls, this behaviour have changed because #920

it crossed my mind that this behaviour was a feature where one could partially match the body, guess that the alternative is to use a custom method when partial match is required or would worth to have an option to bring the wrong but maybe useful behaviour back to live?

in any case, this comment may help others googling about this

@gr2m

This comment has been minimized.

Member

gr2m commented Sep 25, 2017

I run into it myself, but that’s a feature, not a bug. As you mention, you can use a function to partially match a body.

I’ll close the issue because it’s not an open bug

@gr2m gr2m closed this Sep 25, 2017

@nielskrijger

This comment has been minimized.

nielskrijger commented Sep 25, 2017

We were relying on this behaviour in our tests.

I'm now doing this:

import _ from 'lodash';

function matchSubset(actual, partialMatch) {
  let isMatch = true;
  let i = 0;
  const keys = Object.keys(partialMatch);
  while (isMatch && i < keys.length) {
    if (_.isRegExp(partialMatch[keys[i]])) {
      isMatch = partialMatch[keys[i]].test(actual[keys[i]]);
    } else {
      isMatch = actual[keys[i]] === partialMatch[keys[i]];
    }
    i++;
  }
  return isMatch;
}

and in our mock helpers:

mockPost(response, body = undefined) {
  nock('https://some.url')
    .post('/somepath', b => !b || matchSubset(b, body))
    .reply(200, response);
}
@gr2m

This comment has been minimized.

Member

gr2m commented Sep 25, 2017

Thanks @nielskrijger, I’ve created a follow up issue to make the documentation more clear:
#982

Pull Request much appreciated <3

@cristianszwarc

This comment has been minimized.

cristianszwarc commented Sep 25, 2017

@josalmi

This comment has been minimized.

josalmi commented Oct 4, 2017

We were also relying on this in our tests. Maybe 9.0.19 should have been a major release rather than just a patch. http://semver.org/#spec-item-8

@lock

This comment has been minimized.

lock bot commented Sep 13, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if it’s related. Thank you!

@lock lock bot locked as resolved and limited conversation to collaborators Sep 13, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.