5

Ran into an issue running my jests tests where it would error out when importing Airtable

TypeError: Cannot read property 'bind' of undefined

    > 1 | import AirtableAPI from 'airtable'
        | ^
     

      at Object.<anonymous> (node_modules/airtable/src/fetch.ts:5:80)
      at Object.<anonymous> (node_modules/airtable/src/base.ts:5:1)
      at Object.<anonymous> (node_modules/airtable/src/airtable.ts:1:1)
aaronmgdr
  • 598
  • 4
  • 12

1 Answers1

6

error was that fetch was not defined on window. While i was importing fetch for tests i was doing so in the setupFilesAfterEnv so I addd to jest.config `setupFiles: ['./jestSetup.js'],

and in that jestSetup.js

const fetch = require("node-fetch")

global.fetch = window.fetch = fetch;
global.Request = window.Request = fetch.Request;
global.Response = window.Response = fetch.Response;
aaronmgdr
  • 598
  • 4
  • 12