Impossible to mock redirects?
See original GitHub issueI’m trying to mock a redirect structure as follows:
nock('http://www.example.com')
.get('/some-link-1')
.reply(301, undefined, {
Location: 'http://www.example.com/some-link-2'
})
.get('/some-link-2')
.reply(302, undefined, {
Location: 'http://www.example.com/some-link-3'
})
.get('/some-link-3')
.reply(200, 'link');
require('request')({
uri: 'http://www.example.com/some-link-1',
followRedirect : false
}, function (err, res, body) {
console.log(res.statusCode, body);
});
This prints a 200 'link'
. If I try to do this on an unmocked url that redirects, I get a proper 3xx
code. Is there a way to do this with nock
?
Issue Analytics
- State:
- Created 10 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Jest: Trying to mock nested functions and redirects in jest, but ...
In the test file, I am trying to mock logout function. However it is executing someObj.lock function. someObj is not availabe to tests/main.js ......
Read more >Redirecting Mock service's operation - SmartBear Community
Hello. I have a question: is it possible to create a mock service, based on local WSDL, with some operations implemented as a...
Read more >Mocking and testing for RedirectToAction - MSDN - Microsoft
When I do that, the constraint always fails. Rhino Mocks says that null is indeed passed to the Response.Redirect method. There's is little...
Read more >mock trial redirect examination
I've been coaching mock trial for about 12 years now, and every single year, I find that redirect examinations are the last thing...
Read more >Redirect experiments: Test two URLs in Optimizely
Redirect experiments, or split tests, allow you to compare two ... as little delay as possible before a visitor can reach and load...
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 Free
Top 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
@gajus this is the wrong syntax for specifying reply headers. Please see the docs for the proper syntax.
This test works for me:
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if it’s related. Thank you!