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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support exact-matching on FormData bodies #622

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kylekthompson
Copy link

Hello 馃憢

While attempting to mock some client-side calls to fetch using fetch-mock 9.11.0, I was hoping I'd be able to match FormData bodies in addition to JSON. I do see in the docs that it's called out that JSON is supported. Would you be open to a change supporting other kinds of bodies?

The diff as-is will support exact matches of FormData (see the included tests; I've also patched this change locally in my repository as a test and validated that it solves my issues there as well). It also will likely support other exact-matches of bodies (e.g. plaintext), but I've not explicitly called out support for that. I'd be happy to do some work to limit it to FormData only if you'd like (I'll just need to investigate a little more to make it compatible with both client and server environments).

expect(fm.calls(true).length).to.equal(0);
});

it('should not ignore the order of the form fields', async () => {
Copy link
Author

Choose a reason for hiding this comment

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

We might be able to do something more complicated here, but I was a touch worried about the semantics of having multiple values for the same keys/arrays/etc.

We'd probably want to convert the FormData objects to JS objects and compare those as we are today (with isEqual) instead?

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

Successfully merging this pull request may close these issues.

None yet

1 participant