Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Mocha无法在2个文件之间工作_Javascript_Mocha.js - Fatal编程技术网

Javascript Mocha无法在2个文件之间工作

Javascript Mocha无法在2个文件之间工作,javascript,mocha.js,Javascript,Mocha.js,我在使用javascript文件和Mocha的简单测试时遇到了问题 在我的目录中,我有两个文件: test.js 续 cont.js的内容: function testFor5(x){ return x; } module.exports.testFor5 = testFor5; test.js的内容: const assert = require('assert'); const rank = require('./cont.js') describe('test1', function

我在使用javascript文件和Mocha的简单测试时遇到了问题

在我的目录中,我有两个文件: test.js 续

cont.js的内容:

function testFor5(x){
return x;
}

module.exports.testFor5 = testFor5;
test.js的内容:

const assert = require('assert');
const rank = require('./cont.js')

describe('test1', function()  {
  it('it should return the value 5', function(){    
    assert.equal(rank.testFor5(5)==5);
  });
})
在终端中运行moocha test.js时,出现以下错误:

1) test1它应该返回值5:

 AssertionError: true == "undefined"

  at Context.<anonymous> (test.js:7:12)
AssertionError:true==“未定义”
在上下文中。(test.js:7:12)
我已经做了很多教程,但似乎没有一个能处理多个文件


谢谢你的帮助。

这就是断言的工作原理。你把你的价值放在预期的价值上,然后确保你需要摩卡咖啡

assert.equal(rank.testFor5(5), 5);

这就是断言的工作原理,你把你的价值,然后是期望的价值,并确保你需要摩卡咖啡

assert.equal(rank.testFor5(5), 5);