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
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
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);
}
Thanks @nielskrijger, I’ve created a follow up issue to make the documentation more clear:
https://github.com/node-nock/nock/issues/982
Pull Request much appreciated <3
Agree, the function option is the correct way
Thanks everyone
On Tue, 26 Sep 2017 at 07:36 Gregor Martynus notifications@github.com
wrote:
Thanks @nielskrijger https://github.com/nielskrijger, I’ve created a
follow up issue to make the documentation more clear:982 https://github.com/node-nock/nock/issues/982
Pull Request much appreciated <3
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/node-nock/nock/issues/981#issuecomment-331973071, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AEcqkM37LfS_GNcpEJBq6u7j7VNpkJ7Dks5sl_KggaJpZM4PiFMY
.
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
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!
Most helpful comment
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