title: ReferenceError: TextEncoder is not defined with mongoose and jest and typescript
body: <p>I am using Node 14 with express v4.16.3 and typescript (v4.7.4); after adding mongoose (v6.5.2) to the project, the logic code works fine but most of the tests, run by jest (v26.4.2), are failing with error message:</p>
  <p><code>ReferenceError: TextEncoder is not defined.</code>
  The error is thrown from <code>node_modules/mongodb-connection-string-url/node_modules/whatwg-url/lib/encoding.js:2:21</code></p>
  <p>I have read all other questions about this error on SO but none of the solution works for me. A lot of them saying adding
  <code>global.TextEncoder = TextEncoder</code>; but where to do this exactly? I tried to add it to the <code>jest.config.js</code> but didn't make any difference.
  Tried to add it to the file which references <code>mongoose</code> and it says <code>property TextEncoder doesn't exist on global of type Global</code></p>
  <p>A lot of people suggest editing the <code>encoding.js</code> file manually; don't think this is a sustainable solution at all so didn't even try. Some suggest upgrading node to 12 or higher, which doesn't apply to me as I am using node 14.</p>