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

FormData and other xhr send types are converted to plain objects #133

Closed
green3g opened this issue Sep 29, 2017 · 1 comment · Fixed by #141
Closed

FormData and other xhr send types are converted to plain objects #133

green3g opened this issue Sep 29, 2017 · 1 comment · Fixed by #141

Comments

@green3g
Copy link
Contributor

green3g commented Sep 29, 2017

FormData is a valid option for xhr requests and is useful for uploading files. In addition there are other types, like Blob that may be sent via xhr. https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/send

If I have an xhr request like this:

        const data = new FormData();
        for (let i = 0; i < files.length; i++) {
            data.append(i, files.item(i));
        }

            const req = new XMLHttpRequest();
            req.open('POST', this.properties.url, true);
            req.onload = function () {
                if (req.status === 200) {
                    resolve(JSON.parse(req.responseText));
                } else {
                    reject(req);
                }
            };
            req.onerror = reject;
            req.send(data);

The fixture request variable does not allow accessing the FormData properties and fails with

// throws error TypeError: 'entries' called on an object that does not implement interface FormData.

The solution is something like checking to see of the data is an instance of the various data types that can be passed to send. Will submit a pr to demonstrate.

green3g added a commit to green3g/can-fixture that referenced this issue Sep 29, 2017
green3g added a commit to green3g/can-fixture that referenced this issue Sep 29, 2017
@chasenlehara chasenlehara self-assigned this Jan 4, 2018
chasenlehara added a commit that referenced this issue Jan 5, 2018
check for form data types before processing data #133
chasenlehara added a commit that referenced this issue Jan 5, 2018
This makes it so you can send an array as the data for a request and can-fixture won’t turn it into an object.

Closes #133
@chasenlehara
Copy link
Member

This should be fixed in 1.2.2. Thanks @roemhildtg!

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

Successfully merging a pull request may close this issue.

2 participants