Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.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
Node.js 用Should进行阵列测试_Node.js_Should.js - Fatal编程技术网

Node.js 用Should进行阵列测试

Node.js 用Should进行阵列测试,node.js,should.js,Node.js,Should.js,我正在尝试使用节点扩展对该阵列进行测试,该扩展应: {validationError: [{field: 'name', rule: 'string'}, {field: 'name', rule: 'minLength' }, {field: 'name', rule: 'required'}] } 我不知道怎么做 谢谢在项目中创建一个测试文件夹 将下面的文件放入名为FieldsTest.js的文件中 并从项目的根目录运行npm测试 'use strict'; va

我正在尝试使用节点扩展对该阵列进行测试,该扩展应:

{validationError: 
   [{field: 'name', rule: 'string'},
    {field: 'name', rule: 'minLength' },
    {field: 'name', rule: 'required'}] 
}
我不知道怎么做

谢谢

在项目中创建一个测试文件夹

将下面的文件放入名为FieldsTest.js的文件中

并从项目的根目录运行npm测试

'use strict';
var should = require('should');

describe('SO tests', function() {
  it('should pass', function() {
    var x={validationError:
       [{field: 'name', rule: 'string'},
        {field: 'name', rule: 'minLength' },
        {field: 'name', rule: 'required'}]
    };
    x.validationError.forEach(function(y) {
      y.hasOwnProperty("field").should.eql(true);
      y.hasOwnProperty("rule").should.eql(true);
    });
  });

  it('should fail', function() {
    var x={validationError:
       [{field: 'name', rule: 'string'},
        {field: 'name', rule: 'minLength' },
        {field: 'name'}]
    };
    x.validationError.forEach(function(y) {
      y.hasOwnProperty("field").should.eql(true);
      y.hasOwnProperty("rule").should.eql(true);
    });
  });

});

你想测试什么?数组和子数组的所有字段都存在。