node.js - Chai 函数(isAbove、isBelow、ecc)不起作用
问题描述
我正在尝试使用 Mocha 和 Chai 编写测试文件,但 Chai 库似乎不想工作。我肯定做错了什么,但我不明白在哪里。
这是代码
function byte() {}
describe("byteToSignedShort()", function()
{
context("in b argument with the first bit set to 1", function()
{
it("should return a negative number", function()
{
assert.isBelow(byte(), 0, "");
})
})
context("in b argument with the first bit set to 0", function()
{
it("should return a positive number", function()
{
assert.isAtLeast(byte(), 0, "");
})
})
})
我不知道它是否有用,但这是 package.json
{
"name": "learing_typescript",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha -r ts-node/register test/**.ts --recursive --no-deprecation"
},
"author": "",
"license": "UNLICENSED",
"devDependencies": {
"@types/expect": "^24.3.0",
"@types/mocha": "^8.0.3",
"chai": "^4.2.0",
"mocha": "^8.1.3",
"ts-mocha": "^7.0.0",
"ts-node": "^9.0.0",
"typescript": "^4.0.3"
},
"dependencies": {
"@babel/cli": "^7.11.6",
"@babel/core": "^7.11.6",
"@babel/preset-env": "^7.11.5",
"@babel/register": "^7.11.5"
}
}
当我用“npm test”启动它时,会出现这个错误
byteToSignedShort()
in b argument with the first bit set to 1
1) should return a negative number
in b argument with the first bit set to 0
2) should return a positive number
0 passing (16ms)
2 failing
1) byteToSignedShort()
in b argument with the first bit set to 1
should return a negative number:
TypeError: assert.isBelow is not a function
at Context.<anonymous> (test\byteTestDC.ts:10:20)
at processImmediate (internal/timers.js:456:21)
2) byteToSignedShort()
in b argument with the first bit set to 0
should return a positive number:
TypeError: assert.isAtLeast is not a function
at Context.<anonymous> (test\byteTestDC.ts:17:20)
at processImmediate (internal/timers.js:456:21)
解决方案
您可能需要从包中添加assert
导入语句chai
import { assert } from 'chai'; // add import statement
function byte() {}
describe("byteToSignedShort()", function()
{
...
}
推荐阅读
- jenkins - Jenkins Pipeline Plugin 执行外部步骤
- android - 如何在android中实现jwplayer的破折号视频流
- javascript - 如何使用 Nodemailer 发送带有公司域的电子邮件?
- python - pandas:通过将两列数据框与元组列表进行比较来获取行
- sql - 带有嵌套节点的sql xml
- java - 找到第一个匹配的条目并将匹配的条目值分配给变量
- javascript - 将第三方库组装成单独的文件(webpack)
- regex - 如何在单词之间只允许 3 种类型的字符?
- python - 用另一个列表中的元素更新列表元素
- python-3.x - 如何将画布尺寸放入 tkinter 的框架中?