Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.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 cURL命令的Supertest等价物是什么?_Javascript_Node.js_Curl_Jestjs_Supertest - Fatal编程技术网

Javascript cURL命令的Supertest等价物是什么?

Javascript cURL命令的Supertest等价物是什么?,javascript,node.js,curl,jestjs,supertest,Javascript,Node.js,Curl,Jestjs,Supertest,到目前为止,我正在使用Jest和Supertest测试一组代码。我有几个curl命令,如果可能的话,我想用Supertest函数替换它们。我可以检查服务是否在线,但是,我无法测试真正的GET和POST命令。我知道这是可能的,但我不知道如何翻译。到目前为止,我有以下cURL命令: curl -X POST \ 'example.com/v5/data?auth=XXXXXXXXXXXXX&to=foobar@foo.com' \ -F 'images=@/Users/me/Deskto

到目前为止,我正在使用Jest和Supertest测试一组代码。我有几个curl命令,如果可能的话,我想用Supertest函数替换它们。我可以检查服务是否在线,但是,我无法测试真正的GET和POST命令。我知道这是可能的,但我不知道如何翻译。到目前为止,我有以下cURL命令:

curl -X POST \
'example.com/v5/data?auth=XXXXXXXXXXXXX&to=foobar@foo.com' \
  -F 'images=@/Users/me/Desktop/test.png' \
  -F 'details={
          "details": [
            {
                 "summary":"some cool project",
                 "href": "example.com/a/b/c",
            }
        ]
}'
上面的操作完全符合我的要求,但是,下面的supertest函数没有这样做,并且会因超时而失败

let path = 'example.com/v5/data?auth=XXXXXXXXXXXXX&to=foobar@foo.com'
let image = '@/Users/me/Desktop/test.png'
let details = {'details': ['summary':'some cool project', 'href':'example.com/a/b/c']}

// :::::::::: PASSED
it('server online', function(done){
    request(app).get("/")
    .expect(200)
    .expect('<html></html>')
})

// :::::::::: FAILED
it('post test.img', function(done){
    request(app).post(path,object)
    .expect(200)
    .expect('???')
})

// :::::::::: FAILED
it('get test.img', function(done){
    request(app).get(path)
    .expect(200)
    .expect('???')
})
let path='example.com/v5/data?auth=xxxxxxxxxxxx&to=foobar@foo.com'
让image='@/Users/me/Desktop/test.png'
let details={'details':['summary':'some cool project','href':'example.com/a/b/c']}
//:已通过
it('服务器在线',功能(完成){
请求(应用程序)。获取(“/”)
.expect(200)
.expect(“”)
})
//:失败
it('post test.img',函数(完成){
请求(应用程序).post(路径,对象)
.expect(200)
.expect(“???”)
})
//:失败
它('get test.img',函数(完成){
请求(应用)。获取(路径)
.expect(200)
.expect(“???”)
})
我确信我刚刚把所有东西都放错了位置,所以我希望有人能在这里纠正我。

您可以尝试在测试脚本上删除服务器。 它们有许多可读的响应,并且易于理解