How to Persist a request (with cookies, ie sessions) Like super-agent
See original GitHub issueTo access some urls in application, one must login first. I must go back to use super-agent to unit test these urls. Can supertest do thing like this?
server = require './testServer'
request = require 'superagent'
r = request.agent()
server.start 3002
fakeUser =
username:'tj',
password:'foobar'
describe 'after login', ->
beforeEach (done) ->
r
.post("http://localhost:3002/login")
.send(fakeUser)
.end (err, res) ->
assert res.statusCode is 200
done()
it 'can show restricted page', (done) ->
r
.get("http://localhost:3002/restricted")
.end (err, res) ->
assert.include res.text,'Wahoo!'
assert res.statusCode is 200
done()
Issue Analytics
- State:
- Created 11 years ago
- Comments:15 (1 by maintainers)
Top Results From Across the Web
How to Persist a request (with cookies, ie sessions) Like super ...
To access some urls in application, one must login first. I must go back to use super-agent to unit test these urls. Can...
Read more >Superagent share session / cookie info with actual browser
Superagent uses the XMLHttpRequest object in the browser to make http requests. By default, cross-origin requests do not send cookies.
Read more >Maintaining Session State with Cookies | Microsoft Learn
If you want the cookie information to persist beyond the session, you should create a persistent cookie by specifying an expiration date.
Read more >How do I save cookies from an HTTP response so I can send ...
I am trying to collect some data from a website but, in order to do this, I first have to send a post...
Read more >XMLHttpRequest.withCredentials - Web APIs | MDN
The XMLHttpRequest.withCredentials property is a boolean value that indicates whether or not cross-site Access-Control requests should be ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For the records, full example for @alsotang suggest: You don’t need do anything more with the agent.
For the records, full example for @alsotang suggest:
(this is a login form, not an API request)