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, "");
})
})
})

我不知道它是否有用,但这是包.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测试";给我这个错误

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> (testbyteTestDC.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> (testbyteTestDC.ts:17:20)
at processImmediate (internal/timers.js:456:21)

您可能需要从chai包添加assert导入语句

import { assert } from 'chai'; // add import statement
function byte() {}
describe("byteToSignedShort()", function()
{
...
}

相关内容

  • 没有找到相关文章

最新更新