Skip to content
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

fix: mapValues should not update the object in place #2737

Merged
merged 2 commits into from Apr 20, 2024

Conversation

pranaygp
Copy link

@pranaygp pranaygp commented Apr 12, 2024

The original lodash implementation of mapValues is a pure function that doesn't modify the object in place.

The new implementation is causing issues in test cases where the same object is used for the nock response and for validation.

Here's an example of a test that broke when attempting to use the beta

  describe('#patch', () => {
    it('can patch data locally', async () => {
      const patchBody = {name: 'test', id: 1234};

      nock(baseUrl)
        .patch('/', patchBody)
        .reply(200, patchBody);

	  // client#patch uses URL encoding
      const response = await client.patch('/', patchBody);
      should(response.body).eql(patchBody); // breaks
      should(response.statusCode).eql(200);

      should(nock.isDone()).eql(true);
    });
  });

@pranaygp pranaygp changed the base branch from main to beta April 12, 2024 17:28
@pranaygp pranaygp force-pushed the pranaygp/make_map_values_pure branch from 747ad2d to a030393 Compare April 12, 2024 17:29
@pranaygp pranaygp force-pushed the pranaygp/make_map_values_pure branch from ca12cd5 to 7b573e8 Compare April 12, 2024 19:02
@pranaygp pranaygp marked this pull request as ready for review April 12, 2024 19:03
@pranaygp pranaygp changed the title Clone object first in map values fix: mapValues should not update the object in place Apr 12, 2024
@pranaygp
Copy link
Author

cc @mikicho - Not sure if you're the best person to assign for review on this :)

@mikicho
Copy link
Contributor

mikicho commented Apr 18, 2024

@pranaygp Thanks for opening this PR!

What's client in your example? axios? http.get?

@pranaygp
Copy link
Author

It's a custom wrapper around needle

for PATCH requests, we send the data as formdata instead of JSON. That's the triggered the codepath leading to this mapValues implementation

Copy link
Contributor

@mikicho mikicho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for your contribution!

@mikicho mikicho merged commit b37c57f into nock:beta Apr 20, 2024
14 checks passed
Copy link

🎉 This PR is included in version 14.0.0-beta.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants