私はMochaとNodeが初めてですが、いくつかのJavaScriptクラスについていくつかのMochaテストを書こうとしています。Mochaが継承を使用してJavaScriptをテストしています
私は以下のクラスがあります。
function FormField() {
}
FormField.prototype.sanitizeFieldValue = function(value) {
if (value == null || value.replace == null) {
return null;
}
return value
.replace(/ /g, " ")
.replace(/&/g, '&')
.replace(/\\/g, '\\\\')
.replace(/'/g, "\\'")
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/[\n\r]+/g, " ");
};
module.exports = FormField;
私は、このファイルに私のモカ・テストを実行すると、すべてが正常に動作し、テストに合格します。
var expect = require("chai").expect;
var formfield = require("FormField");
describe("new Form Field Tests", function() {
var ff = new formfield();
describe("sanitizeFieldValue", function() {
it("escapes apostrophe", function() {
expect(ff.sanitizeFieldValue("'")).to.equal("\\\'");
});
});
});
はしかし、私が最初に参照する別のファイルがあります:
TargetDateField.prototype = new FormField();
function TargetDateField() {
// some functions
}
module.exports = TargetDateField;
をしかし、私は次のことを試してみましたが、私はフォームフィールドが定義されていない得続ける方法この をテストすることを確認していません。
var expect = require("chai").expect;
var FormField = require("FormField").FormField;
var targetdatefield = require("TargetDateField");
これを解決する方法はありますか?