1

我正在关注 NodeJS Twilio SDK 文档,内容如下:

const twilio = require('twilio')

exports.sendActivationCode = async (phone, activationCode) => {
  const accountSID = '<REDACTED>'
  const authToken = '<REDACTED>'
  const client = twilio(accountSID, authToken)
  return await client.messages.create({
    body: `Your activation code is ${activationCode}`,
    from: '+1<REDACTED>',
    to: `+1${phone.toString().replace(/\D/g, '')}`
  })
}

我已经检查了很多次,以确保我与文档直接匹配。当我尝试运行我得到的代码时Error: Headers User-Agent forbidden。请求本身显示 header is out:'User-Agent': 'twilio-node/3.45.0 (node.js v10.15.3)'并且堆栈输出表明这是来自jsdom-> xhr-utils

4

1 回答 1

1

这就是为我解决的问题。只需将以下内容添加到您的package.json文件中。

    "jest": {
      "testEnvironment": "node"
    },

在这里找到: https ://medium.com/@kevinsimper/how-to-disable-jsdom-in-jest-make-jest-run-twice-as-fast-a01193f23405

于 2020-06-30T02:59:56.663 回答