【发布时间】:2015-12-08 09:56:55
【问题描述】:
我正在尝试向https://github.com/visionmedia/supertest 添加一些方便的方法。到目前为止,我能够做到的唯一方法是将它们直接添加到 lib/test.js 中的模块源代码中:
Test.prototype.expectHeaders = function (a)
{
for (var header in a)
{
this._asserts.push(this._assertHeader.bind(this,
{
name: '' + header,
value: a[header]
}));
}
return this;
};
我通过 util.inherits 和prototype.__proto__ 进行了尝试,但每次尝试都以“expectHeaders is not a function”异常结束。
这是我最近的尝试:
var supertest = require('supertest'),
util = require('util');
var SccTest = function()
{
};
SccTest.prototype.__proto__ = supertest.prototype;
SccTest.expectHeaders = function (a)
{
for (var header in a)
{
this._asserts.push(this._assertHeader.bind(this,
{
name: '' + header,
value: a[header]
}));
}
return this;
};
util.inherits(SccTest, supertest);
module.exports = SccTest;
如何正确地将方法添加到测试原型?
【问题讨论】:
标签: javascript node.js supertest