Jest returns “Network Error” when doing an authenticated request with axios

后端 未结 4 589
被撕碎了的回忆
被撕碎了的回忆 2021-02-02 09:14

This seems a bit weird to me. I\'m trying to test an actual (ie. real network) request with Jest.

These are the tested scenarios:

  • Test an external API (fix
4条回答
  •  北海茫月
    2021-02-02 09:35

    I resolved it by adding

    axios.defaults.adapter = require('axios/lib/adapters/http');
    

    for a specific test case file, as setting global.XMLHttpRequest = undefined or env=node was causing my other test cases to fail.

提交回复
热议问题