私はJavaScriptで開発を始めましたが、概念(js、ノード、バスターなど)を分離するのにまだ問題があります。質問が正確に正しい範囲にない場合はご容赦ください。
私は js アプリケーションを開発しようとしていますが、テスト駆動型のアプローチが必要です。
これは、js フォルダーで定義する単純なオブジェクトです。
var Friend = (function(name, email){
console.log(name)
if (typeof(name) != "string") throw "Expected a string for name"
this.name = name;
this.email = email;
}());
module.exports = Friend(name, email);
私のテストフォルダーでは、friend_test.jsを使用してテストしたい
var buster = require("buster");
var Friend = require('/../js/friend');
buster.testCase("A normal Friend", {
"should have a name and a mail": function(){
var my_friend = new Friend("Georges", "georges@hotmail.com");
assert.equals(my_friend.name, "Georges");
assert.equals(my_friend.email, "georges@hotmail.com");
}
});
ここでの私の懸念は、テストを実行すると、入力パラメーターが渡されなかった場合と同様に、名前と電子メールが友人内で認識されないことです。
$ node test/friend-test.js
undefined
undefined
friend.js:4
if (typeof(name) != "string") throw "Expected a string for name"
^
Expected a string for name
私は何を間違っていますか?
どうも、