Giter Club home page Giter Club logo

Comments (5)

keithamus avatar keithamus commented on June 29, 2024 2

By default it seems SuperAgent (which is what Chai-HTTP uses for requests) follows redirects, meanwhile .redirect and .redirectTo assert that the response has not followed any redirects.

In the new (upcoming) version of Chai-HTTP - you can run chai.request(app).get('/').redirects(0) to ensure SuperAgent doesn't ever follow any redirects, at which point the .redirect and .redirectTo tests should work.

It might be worth extending .redirect and .redirectTo to first check for a 3xx status code, but to also check if res.redirects exists and see if it contains the URL - basically completing the logic you have done manually.

from chai-http.

Guuz avatar Guuz commented on June 29, 2024 1

Updated to the latest version and used .redirects(0). Note that this is not in the documentation and i only got it to work because i read this issue again. Adding it to the docs should help new users find this easily.

from chai-http.

keithamus avatar keithamus commented on June 29, 2024

I'm going to re-open this @Guuz because you're right - something needs to change, be it docs or code.

from chai-http.

Guuz avatar Guuz commented on June 29, 2024

Thanks :)

from chai-http.

hurrymaplelad avatar hurrymaplelad commented on June 29, 2024

Checking res.redirects makes sense to me, since we bundle SuperAgent, but let's not depend on it. I use chai-http with request and had configured it with followRedirect: false.

from chai-http.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.