forwardemail / forwardemail/superagent

Node version is used in JSDOM environment

Open
#1,531 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
16.6k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

I was trying to figure out why mocking XHR wasn't affecting superagent requests when running my unit tests with Jest. After much debugging it turns out the node version of superagent was getting used in my test environment instead of the browser version. JSDOM emulates the browser environment so it seems incorrect that the node version would get loaded here.

A workaround is to set jests's `moduleNameMapper` like this in your jest config file:
```js
moduleNameMapper: {
// use browser version of superagent
superagent: 'superagent/dist/superagent'
},
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.