Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.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/8/sorting/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
Node.js 如何模拟Strongloop';s使用Supertest/Superagent更新方法?_Node.js_Mocha.js_Loopbackjs_Strongloop_Superagent - Fatal编程技术网

Node.js 如何模拟Strongloop';s使用Supertest/Superagent更新方法?

Node.js 如何模拟Strongloop';s使用Supertest/Superagent更新方法?,node.js,mocha.js,loopbackjs,strongloop,superagent,Node.js,Mocha.js,Loopbackjs,Strongloop,Superagent,我正在使用supertest和mocha为strongloop/loopback API进行一些测试。标准端点之一是Model/update。更新实际上是一种形式,它接收查询,然后发布到与查询匹配的所有条目。这是一张成功请求在资源管理器中的外观图片: 请注意,从图片中可以看出,请求URL主要只是一个查询字符串,它返回204。我从superagent那里知道,你可以用帖子提交查询。然而,我在复制我的测试时遇到了很多麻烦。 以下是我的要求声明: var request = require('sup

我正在使用supertest和mocha为strongloop/loopback API进行一些测试。标准端点之一是Model/update。更新实际上是一种形式,它接收查询,然后发布到与查询匹配的所有条目。这是一张成功请求在资源管理器中的外观图片:

请注意,从图片中可以看出,请求URL主要只是一个查询字符串,它返回204。我从superagent那里知道,你可以用帖子提交查询。然而,我在复制我的测试时遇到了很多麻烦。 以下是我的要求声明:

var request = require('supertest');
var app = require('../server');
var assert = require('chai').assert;
var chance = require('chance').Chance();
这是我的测试

describe('/api/Points/update', function(){
    var updatedZip = "60000";

it('should grab a Point for a before reference', function(done) {
   json('get', '/api/Points/' +addID )
   .end(function(err, res) {
       assert.equal(res.body.zipcode, addZip, 'unexpected value for zip');   
      done();
    });
  });
it('should update the Point w/ a new zipcode', function(done) {
   var where = {"zipcode": "60035"}; 
   var data ={"zipcode": updatedZip};

   request(app)
    .post('/api/Points/update')
    .query({"where": {"zipcode": "60035"}})
    .send({                 
       data : data
     })
   .end(function(err, res) {
       assert.equal(res.status, 204, 'update didnt take');
       done();
      });
    });
it('should check to see that the Point was updated', function(done) {
  json('get', '/api/Points/' +addID )
  .end(function(err, res) {
      assert.equal(res.body.zipcode, updatedZip, 'updated zip was not applied');    
   done();
  });
});

第一个测试通过,这意味着它返回204作为请求的状态,但是第二个测试失败,这意味着即使它发现查询可以接受,它实际上也没有应用更新。我试过许多不同的配方,但都不管用。请让我知道我怎么可能模拟这个!提前感谢您的帮助

只是猜测一下,这可能是因为作为
.query({where:})
的值的数据需要进行字符串化/转义,而supertest可能不会为您做什么?因此,请尝试:
.query({“where”:“%7B%22zipcode%22%3A%20%2260035%22%7D%0A”})
可能只是猜测,可能是因为作为
.query({where:})
的值的数据需要进行字符串化/转义,而supertest可能不会为您做些什么?因此,请尝试:
.query({“where”:“%7B%22zipcode%22%3A%20%2260035%22%7D%0A”})
可能只是猜测,可能是因为作为
.query({where:})
的值的数据需要进行字符串化/转义,而supertest可能不会为您做些什么?因此,请尝试:
.query({“where”:“%7B%22zipcode%22%3A%20%2260035%22%7D%0A”)
也许。。。