React native 使用Jest的单元测试给出TypeError:File.Test.js:无法读取属性';toString';未定义的

React native 使用Jest的单元测试给出TypeError:File.Test.js:无法读取属性';toString';未定义的,react-native,jestjs,expo,babeljs,babel-jest,React Native,Jestjs,Expo,Babeljs,Babel Jest,我一直使用Expo CLI在React Native中工作,最近开始面临由于一个常见原因导致单元测试失败的问题。堆栈跟踪在下面 Cannot read property 'toString' of undefined at Converter.toBase64 (node_modules/convert-source-map/index.js:61:46) at Converter.toComment (node_modules/convert-source-map/i

我一直使用Expo CLI在React Native中工作,最近开始面临由于一个常见原因导致单元测试失败的问题。堆栈跟踪在下面

Cannot read property 'toString' of undefined

      at Converter.toBase64 (node_modules/convert-source-map/index.js:61:46)
      at Converter.toComment (node_modules/convert-source-map/index.js:65:21)
      at generateCode (node_modules/@babel/core/lib/transformation/file/generate.js:78:76)
      at run (node_modules/@babel/core/lib/transformation/index.js:55:33)
          at run.next (<anonymous>)
      at transform (node_modules/@babel/core/lib/transform.js:27:41)
          at transform.next (<anonymous>)
      at evaluateSync (node_modules/gensync/index.js:244:28)
      at sync (node_modules/gensync/index.js:84:14)

对于你们这些仍然徘徊在寻找上述问题答案的人。 问题在于库本身转换源映射时需要处理此异常

我分叉了实际的存储库,并在第64行toBase64方法中处理了该异常。现在这个方法看起来像是

Converter.prototype.toBase64 = function () {
  var json = this.toJSON();
  return (SafeBuffer.Buffer.from(json, 'utf8') || "").toString('base64');
};
现在一切正常

最初的方法是这样的

Converter.prototype.toBase64 = function () {
  var json = this.toJSON();
  return SafeBuffer.Buffer.from(json, 'utf8').toString('base64');
};
Converter.prototype.toBase64 = function () {
  var json = this.toJSON();
  return SafeBuffer.Buffer.from(json, 'utf8').toString('base64');
};