在Jest中运行Axios测试时出现follow-redirects排除警告的问题
Jest测试Axios时出现follow-redirects警告的问题
Warning: exclude follow-redirects from browser builds
重现步骤
- Node.js项目使用Axios发起HTTP请求
- 运行涉及Axios(如
axios.get())的Jest测试时,控制台始终显示该警告 - 测试本身可以通过,但每次都会出现该警告
已尝试方案
- 确保Jest配置中设置了
testEnvironment: 'node' - 尝试Mock Axios和follow-redirects模块以规避问题
- 检查Jest配置确保未触发浏览器特定构建,但警告仍在所有测试文件中出现
- 运行
npm ls follow-redirects后确认只有Axios直接依赖该包
环境信息
- Axios版本:1.7.7
- Jest版本:29.7.0
内容的提问来源于stack exchange,提问作者i am just learner
相关产品推荐
相关产品推荐

