You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 12:25:55