Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.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 如何在同一js文件中的descripe()内部的descripe()外部定义导出来调用函数_Javascript_Mocha.js - Fatal编程技术网

Javascript 如何在同一js文件中的descripe()内部的descripe()外部定义导出来调用函数

Javascript 如何在同一js文件中的descripe()内部的descripe()外部定义导出来调用函数,javascript,mocha.js,Javascript,Mocha.js,我想写点像这样的东西 describe('Create User', function () { it('1: All Data Valid', function (done) { servicesGenerator.postPlayoApi(apiEndPoints.createUser) .send(this.getValidUserCreateBody()) .end(function (err, res) { validator.userDataT

我想写点像这样的东西

describe('Create User', function () {
  it('1: All Data Valid', function (done) {
    servicesGenerator.postPlayoApi(apiEndPoints.createUser)
    .send(this.getValidUserCreateBody())
    .end(function (err, res) {
      validator.userDataTypeValidator(err, res);
      done();
    });
  });
});

exports.getValidUserCreateBody = function() {
  return {
    "emailId": testData.emailIdDefault,
    "fName": testData.fNameDefault,
    "lName": testData.lNameDefault,
    "gender": testData.genderDefault,   
  };
}
但是它的给定错误是:this.getValidUserCreateBody不是一个函数 我应该如何继续执行此流程?

明白了。请在描述上方定义
getValidUserCreateBody

此外,函数中的
与函数外部的
不同。尝试通过闭包使用
getValidUserCreateBody

var getValidUserCreateBody = function() {
  return {
    "emailId": testData.emailIdDefault,
    "fName": testData.fNameDefault,
    "lName": testData.lNameDefault,
    "gender": testData.genderDefault,   
  };
}

exports.getValidUserCreateBody = getValidUserCreateBody; //You don't necessarily need this line if you don't use it outside this file.

describe('Create User', function () {
  it('1: All Data Valid', function (done) {
    servicesGenerator.postPlayoApi(apiEndPoints.createUser)
    .send(getValidUserCreateBody())
    .end(function (err, res) {
      validator.userDataTypeValidator(err, res);
      done();
    });
  });
});
始终使用“使用严格”快速定位问题