获取TypeError:这不是在Mocha中使用Buffer.from的类型化数组 [英] Getting TypeError: this is not a typed array using Buffer.from in mocha

查看:79
本文介绍了获取TypeError:这不是在Mocha中使用Buffer.from的类型化数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Mocha/Chai对一个库进行单元测试,该库最近开始使用nodejs的Buffer对象来解决另一个问题.

I'm using Mocha / Chai to unit test a library that has recently started using nodejs' Buffer objects to solve a different problem.

我在单元测试中收到以下错误消息:

I get this error message in the unit test:

TypeError: this is not a typed array. 
at Function.from (native) 
at Object.hashesMatch (index.js:29:18
at Context.<anonymous> (test/test.js:25:22)

index.js的第29行是我正在使用nodejs的Buffer ...

Line 29 of index.js is where I'm using nodejs' Buffer...

var b = Buffer.from ('some string or other');

我找不到polyfill或变通办法,因此非常感谢您提出建议.

I can't find a polyfill or workaround so would be grateful for suggestions.

谢谢

推荐答案

您可能正在使用旧版本的Node.js.

You might be using an old version of Node.js.

Buffer.from 在6.0.0版中引入:

为了使Buffer对象的创建更可靠且更不易出错,新的Buffer()构造函数的各种形式已被弃用,并由单独的Buffer.from(),Buffer.alloc()和Buffer.allocUnsafe代替()方法.

To make the creation of Buffer objects more reliable and less error prone, the various forms of the new Buffer() constructor have been deprecated and replaced by separate Buffer.from(), Buffer.alloc(), and Buffer.allocUnsafe() methods.

文档编制的先前版本中没有对此方法的引用.

There's no reference to this method in previous versions of documentiation.

您可以更新到6.0.0,也可以使用不赞成使用的构造函数API,该API具有以下签名:

You could either update to 6.0.0 or use a deprecated constructor API, which has the following signature:

new Buffer(str[, encoding])

这篇关于获取TypeError:这不是在Mocha中使用Buffer.from的类型化数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆