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

Mock status code equals zero #239

Open
VitaliyShevchenko opened this issue Nov 23, 2018 · 0 comments
Open

Mock status code equals zero #239

VitaliyShevchenko opened this issue Nov 23, 2018 · 0 comments

Comments

@VitaliyShevchenko
Copy link

VitaliyShevchenko commented Nov 23, 2018

I tried to mock response like below:

this.put('some-url', function (req) {
    return [0, "error", ''];
  });

Buuut, in my response handler, I got statusCode = 200. After some debugging, I discovered that, it's because of new jquery(my version is 3.3.1), that has some code like below:

complete(
		xhrSuccessStatus[ xhr.status ] || xhr.status,
		xhr.statusText,

		// Support: IE <=9 only
		// IE9 has no XHR2 but throws on binary (trac-11426)
		// For XHR2 non-text, let the caller handle it (gh-2498)
		( xhr.responseType || "text" ) !== "text"  ||
		typeof xhr.responseText !== "string" ?
		{ binary: xhr.response } :
		{ text: xhr.responseText },
		xhr.getAllResponseHeaders()
		);

where xhrSuccessStatus equals:

var xhrSuccessStatus = {

		// File protocol always yields status code 0, assume 200
		0: 200,

		// Support: IE <=9 only
		// #1450: sometimes IE returns 1223 when it should be 204
		1223: 204
	}

So, when xhr.status eqauls 0, I got status as 200.
any minds about that?
probably, someone has any workarounds for that?

Thanks!

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

No branches or pull requests

1 participant