gpt4 book ai didi

javascript - 我在以下 chai Expect 中收到断言错误

转载 作者:行者123 更新时间:2023-12-03 00:13:42 30 4
gpt4 key购买 nike

所以我尝试添加两种数据类型,看看它们会产生什么结果。例如,我想要 1 + 1 给我 2 和 1 +“one” 给我“1one”。这是我的functions.js 文件:

module.exports = {
addingTwoDataTypes(one, two) {
return (one + two);
}
};

这是我的测试文件:

var expect = require("chai").expect;
var functions = require("../lib/functions")

describe("addingTwoDataTypes()", function () {
it("should return the sum of two numbers", function() {
var results = functions.addingTwoDataTypes(2 + 2);
expect(results).to.equal(4);
});
});

运行测试后出现以下错误:

addingTwoDataTypes()
1) should return the sum of two numbers


0 passing (12ms)
1 failing

1) addingTwoDataTypes()
should return the sum of two numbers:

AssertionError: expected NaN to equal 4
+ expected - actual

-NaN
+4

at Context.<anonymous> (test/test.js:7:26)



npm ERR! Test failed. See above for more details.

最佳答案

你正在调用一个函数,var results = functions.addingTwoDataTypes(2 + 2); 应为 (2,2) 而不是 (2 + 2)。您正在将 (4, undefined) 发送到您的函数

关于javascript - 我在以下 chai Expect 中收到断言错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54610888/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com