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
Node.js 有没有办法用Jasmine NodeJS发送JPG?_Node.js_Jasmine_Frisby.js - Fatal编程技术网

Node.js 有没有办法用Jasmine NodeJS发送JPG?

Node.js 有没有办法用Jasmine NodeJS发送JPG?,node.js,jasmine,frisby.js,Node.js,Jasmine,Frisby.js,我正在尝试使用FrisbyJS(它位于Jasmine for Node的顶部)测试我的API。我想知道是否有人知道如何使用Jasmine提交/发送图像 我现在的代码是 var frisby = require('frisby'); var URL = 'http://localhost/api'; frisby.globalSetup({ request: { headers: { 'Content-Type': 'application/x-www-form-urlenco

我正在尝试使用FrisbyJS(它位于Jasmine for Node的顶部)测试我的API。我想知道是否有人知道如何使用Jasmine提交/发送图像

我现在的代码是

var frisby = require('frisby');

var URL = 'http://localhost/api';

frisby.globalSetup({
  request: {
  headers: {
   'Content-Type': 'application/x-www-form-urlencoded',
   'Accept': 'application/json',
   'api': 'key'
  }
 },
 timeout: (30 * 1000)
});

frisby.create('submit an image')
  .post(URL + 'image', {images: '@test.jpg'}, {method: 'POST'})
  .expectStatus(200)
  .afterJSON(function(cart){
    console.log('made it!');
  })
}).toss();
我得到以下错误:

  1) Frisby Test: submit an image
[ POST http://localhost/api ]
  Message:
   timeout: timed out after 30000 msec waiting for HTTP Request timed out before completing
   Stacktrace:
    undefined

    Finished in 31.458 seconds

是的,image test.jpg确实存在于与spec文件相同的文件夹中:),并且我正在执行spec本身(jasmine节点。)。

我根据


嗨,你能找到解决方案吗?我也遇到了同样的问题,最终使用了restler,一个更好的frisbyjs替代品。在restler的文档中,你可以看到如何使用发送的数据发送图像。
var frisby = require('frisby');
var fs = require('fs');
var path = require('path');
var FormData = require('form-data');

var contentPath = path.resolve(__dirname, './path/to/image.jpg');    
var form = new FormData();

form.append('file', fs.createReadStream(contentPath), {
  knownLength: fs.statSync(contentPath).size
});

frisby.create('Create content asset')
  .post(apiPath + '/assets', form, {
     json: false,
     headers: {
       'content-type': 'multipart/form-data; boundary=' + form.getBoundary(),
       'content-length': form.getLengthSync(),
     }
})
.expectStatus(201)
.toss()