有没有办法在supertest中设置默认值?

ase*_*ami 7 javascript rest json node.js supertest

我正在使用supertest模块来测试我的Rest API.我的API一直发送JSON.所以我正在做.expect('Content-Type', /json/)所有和每个测试!我一次又一次地重复着!

这是我的一些代码

it('should list ALL permissions on /permissions GET', (done)=> {
    request(app)
        .get( permissionsURL )
        .expect(200)
        .expect('Content-Type', /json/)
        .end((err, res)=> {
            var permissions = res.body;
            permissions.should.be.an.instanceOf(Array);
            var permission = permissions[0];
            permission.should.be.json;
            permission.should.have.properties(['name', '_id']);
            permission.name.should.be.a.String();
            // permission.should.not.have.property('__v');

            done(err);
        });
});

it('should list a SINGLE permission on /permissions/<id> GET', (done)=> {
    request(app)
        .get( permissionsURL +savedPermissionId )
        .expect(200)
        .expect('Content-Type', /json/)
        .end((err, res)=> {
            var permission = res.body;
            permission.should.be.json;
            permission.should.have.properties(['name', '_id']);
            permission.name.should.be.a.String();
            // permission.should.not.have.property('__v')

            done(err);
        });
});
Run Code Online (Sandbox Code Playgroud)

还有其他方法吗?像superagent-defaults模块一样思考但是对于supertest而言不是超级的?或者是否可以使用superagent-defaults with supertest?

感谢您提供的任何帮助.:)

Har*_*ner 1

无法为所有测试设置此值。但是,如果您可以考虑为每个希望返回 JSON 的端点进行一套测试,并且只在其中进行此 Expect 调用,那么您可以省略每个其他测试的 Expect。