所以我试图添加两种数据类型并查看它们的结果。例如,我希望 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)
你发送到你的函数
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句