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

Regression in v5.0.8+ fakeServer when $.ajax() XHR includes headers #1817

Closed
scottohara opened this issue May 31, 2018 · 4 comments
Closed

Comments

@scottohara
Copy link

Describe the bug
In sinon@5.0.7, using jQuery's $.ajax() to fetch a non-existent URL from fakeServer returns a 404 Not Found response, as expected.

In sinon@5.0.8 and later, the same fetch now returns a 0 status.

To Reproduce

  1. npm install sinon@5.0.7, and run the tests below
  2. npm install sinon@5.0.8, and re-run the tests again
describe.only("404 Not Found", () => {
  let fakeServer;

  beforeEach(() => (fakeServer = sinon.fakeServer.create({respondImmediately: true})));

  it("should work without headers", done => {
    $.ajax({
      url: "/bad",
      headers: {},
      error(response) {
        response.status.should.equal(404);
        response.statusText.should.equal("Not Found");
        done();
      }
    });
  });

  it("should work with headers", done => {
    $.ajax({
      url: "/bad",
      headers: {"X-FOO": 1},
      error(response) {
        response.status.should.equal(404);
        response.statusText.should.equal("Not Found");
        done();
      }
    });
  });

  afterEach(() => fakeServer.restore());
});

Expected behavior
The specs above create a fakeServer and then attempt to fetch a non-existant URL (/bad).
The only difference between the two specs is the second includes a request header, X-FOO: 1.
The specs assert the response returned from fakeServer is a 404 Not Found

In sinon@5.0.7, both specs pass.
In sinon@5.0.8 and later, the spec with the X-FOO request header fails

Screenshots
Results from sinon@5.0.7:
5_0_7

Results from sinon@5.0.8:
5_0_8

Context (please complete the following information):

  • Library version: 5.0.8+
  • Environment:
  • Example URL:
  • Other libraries you are using: jquery@3.3.1, webpack@4.10.2, chai@4.1.2, mocha@5.2.0
@fatso83
Copy link
Contributor

fatso83 commented May 31, 2018

Probably happened in 082f8e8, going from nise@1.2.0 to nise@1.3.3. Moving this issue over to the nise subproject.

@fatso83
Copy link
Contributor

fatso83 commented May 31, 2018

This issue was moved to sinonjs/nise#51

@fatso83
Copy link
Contributor

fatso83 commented May 31, 2018

This issue was moved to sinonjs/nise#52

@fatso83
Copy link
Contributor

fatso83 commented May 31, 2018

Thanks, @scottohara!

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

2 participants