Tag: 超类

如何使用supertesttestingPOST请求参数Express应用程序?

我使用Express 4.0.0创build一个API,其中一个路由需要一个POST。 目前我只是试图让它响应在请求参数中发送的名称。 响应是一个JSON对象,但请求需要表单域。 users.post '/user', (req, res) -> res.json name: req.params.name 我的testing设置type() form应该允许send()传递散列作为POST参数/字段。 describe 'POST /user', -> it 'should echo the name sent', (done) -> request app .post '/user' .type 'form' .send name: 'Foo' .expect '{"name":"Foo"}' .end done 无论如何,我的testing失败了,在Express中,我的req.params是空的, req.param('name')是undefined , req.body也是空的。 有没有一些req.fields属性我不知道,或者是我的testing瑕疵?

如何在没有空callback的情况下testing多个调用

我有一个场景,我想在单个testing中对Express服务的Node.js服务进行多个REST调用,即: var request = require('supertest'), should = require('should'), game = require('../game.js').app; describe('single pin game of bowling', function(done) { it('should return 20', function(done) { for(var i = 0; i < 20; i++) { request(game).post('/bowl/1').expect(200, function(){}); } request(game).get('/score').expect('20', done); }); }); 在这个阶段,POST调用会增加/score返回的值。 虽然这个testing通过,有没有办法消除POST期望中的空callback函数? 如果我没有回叫,分数返回0,testing失败。 如果我使用done作为callback,我得到一个错误,因为完成调用多次。

Node.js supertest发布gzip压缩的数据

我想写一个testing发布一些压缩的数据到一个URL如下,但它不工作: zlib.gzip('foo_bar_data', function (err, buffer) { request(app) .post('/foo/bar') .set('Content-Encoding', 'gzip') .send(buffer) .expect(200) .end(function(err, res){ if (err) return done(err); //various other validations here done(); }); }); 我认为问题是发送不接受缓冲区。 我仍然希望expect()和end()方法能够正常工作。

使用supertest和async.parallel发送并行http请求?

在并行/并发请求发送到应用程序时,我发现了一个有趣的问题,这个问题在探索性testing中发生。 我试图用supertest复制testing自动化的情况下,但我做错了使用asynchronous库。 任何人都可以让我知道我失踪了吗? it('will handle concurrent GET requests', function(done){ var asyncTasks = []; for (i = 0; i < 30; i++){ asyncTasks.push(function(done){ agent.get('url') .set('headerHere', 'someVal') .send('') .expect(200, done); }) }; async.parallel(asyncTasks, function(){ done(); }); }) 它或者不是断言预期的代码,或者根本不能说明任务。

Supertest + Express不会失败

这或多或less是超级testingexpression中间件的副本 但一年后,我想我会开始一个新的问题。 var express = require('express'); var request = require('supertest'); var app1 = express(); app1.get('/myapp', function (req, res) { res.send(200, { name: 'myapp' }); }); request = request(app1); it('should fail', function () { request .get('/hahahahahahahaha') .expect(123); }); 据我所知,这总是会错误地通过。 path错误并期待不同的状态码这一事实并不重要。 而且 – 更一般地(没有Express),它看起来总是通过: it('should fail', function () { request('http://thisdoesnotexist.mydomain') .get() .expect(200); }); 这也不起作用: it('should fail', function […]

无法通过authentication从supertest上传文件到multer

我正在使用multer来处理我的快速应用程序中的file upload,而且我还使用node-sspi进行ntlm身份validation。 当用curl上传文件时,一切正常。 但是,当我尝试与超级相同,这是行不通的。 Supertest只使用auth或只是上传,但我没有成功与他们在一起工作。 curl命令: curl -u user:pass –ntlm -F upload=@filename http://localhost 超级代码不起作用: request(app) .post('/upload') .auth(username, password) .attach('upload', fileToUpload) .expect(200) 如果我省略了attach或auth – 它的工作原理(当然,我需要禁用服务器端的身份validation,但通常我可以上传) 那么,有人知道如何使用超级用户身份上传文件auth?

在快速响应对象上获取Cookie数据?

我只是做了一些APItesting,我试图validation发送的cookie数据是正确的,但是我找不到有关从响应对象获取cookie的任何文档,只能从请求中获取。 那么是否有一个快速的方法来做到这一点,就像你会做的请求req.cookies["myCookie"] ,我知道我可以得到标题,并从那里得到一个集的cookie,但它有点混乱试图从那里手动parsing出来的cookie数据。

超级testing表示中间件

发现以下关于如何testing中间件的提示: https://github.com/visionmedia/express/blob/master/test/req.xhr.js 我想知道为什么我的testing总是通过。 直到我注意到,当我从expression复制testing他们performance相同。 我试图搞砸了,但他们不断传递: https : //github.com/visionmedia/express/blob/master/test/req.xhr.js 我在这里错过了什么? it('should return true when X-Requested-With is xmlhttprequest', function(done){ var app = express(); app.use(function(req, res){ req.xhr.should.be.false; //set to false, to fail the test but it still passes res.end(); }); request(app) .get('/') .set('X-Requested-With', 'xmlhttprequest') .end(function(res){ done(); }) })

试图使用supertest来检查响应的主体 – 得到一个错误

我正在尝试使用supertest进行一些testing。 这是我想要testing的代码片段: it("should create a new org with valid privileges and input with status 201", function(done) { request(app) .post("/orgs") .send({ name: "new_org", owner: "oldschool@aol.com", timezone: "America/New_York", currency: "USD"}) .expect(201) .end(function(err, res) { res.body.should.include("new_org"); done(); }); }); 尝试testingres体时出现错误: TypeError: Object #<Object> has no method 'indexOf' at Object.Assertion.include (../api/node_modules/should/lib/should.js:508:21) at request.post.send.name (../api/test/orgs/routes.js:24:27) at Test.assert (../api/node_modules/supertest/lib/test.js:195:3) at Test.end […]