因此,我尝试添加两个数据类型,并查看它们的结果。例如,我希望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.
答案 0 :(得分:0)
对不起,愚蠢的错误。
错误:
var results = functions.addingTwoDataTypes(2 + 2);
正确:
var results = functions.addingTwoDataTypes(2, 2);
答案 1 :(得分:0)
您正在调用一个函数,
var results = functions.addingTwoDataTypes(2 + 2);
应该是(2,2)
而不是(2 + 2)
。
您正在向函数发送(4, undefined)