我在运行jest测试时遇到了一个问题,在导入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)发布于 2021-03-17 06:00:29
错误是未在window上定义提取。当我为测试导入fetch时,我在setupFilesAfterEnv中这样做,所以我添加到jest.config‘`setupFiles:'./jestSetup.js',
在该jestSetup.js中
const fetch = require("node-fetch")
global.fetch = window.fetch = fetch;
global.Request = window.Request = fetch.Request;
global.Response = window.Response = fetch.Response;https://stackoverflow.com/questions/66664004
复制相似问题