私は、基本的なhttpテストを誓いで機能させることを試みている時間のドゥージーを持っています。
私は誓いhttp://vowsjs.org/#-writing-asynchronous-testsの非同期の例に従い、適切な呼び出しに置き換えたと思いますが、何かが足りないに違いありません。
テストコードは次のようになります。
var http = require('http'),
vows = require('vows'),
assert = require('assert');
vows.describe("homepage").addBatch({
"Get the home page": {
topic: function() {
http.get({'host': "127.0.0.1", 'port': 5000, 'path': '/'}, this.callback);
},
'should respond with 200 OK': function(res) {
assert.equal(res.statusCode, 200);
}
}
}).export(module);
このテストを実行しようとすると、次のエラーが発生します。
/Users/<home_folder>/node_modules/vows/lib/vows.js:80
rrored', { type: 'promise', error: err.stack || err.message || JSON.stringify(
^
TypeError: Converting circular structure to JSON
at Object.stringify (native)
at EventEmitter.<anonymous> (/Users/<home_folder>/node_modules/vows/lib/vows.js:80:90)
at EventEmitter.emit (events.js:64:17)
at /Users/<home_folder>/node_modules/vows/lib/vows/context.js:31:52
at ClientRequest.<anonymous> (/Users/<home_folder>/node_modules/vows/lib/vows/context.js:46:29)
at ClientRequest.g (events.js:143:14)
at ClientRequest.emit (events.js:64:17)
at HTTPParser.onIncoming (http.js:1349:9)
at HTTPParser.onHeadersComplete (http.js:108:31)
at Socket.ondata (http.js:1226:22)
簡単なhttpの例を取得して、それ自体で機能させることができます。誓いの例をそれ自体で機能させることはできますが、何らかの理由でそれらを組み合わせることができません。ここで助けていただければ幸いです。私はこれをしばらくの間機能させようとしています(多くのグーグルを含む)。
アップデート:
Alexis Sellier(誓いの作成者)の助けを借りて、コールバックにエラー引数を追加すると、この問題が解決するようです。
しかし、その理由はわかりません。http libの例をそれ自体で書き出す場合、エラー引数は必要ありません。なぜそれが必要なのかを示す誓いの文書が見つからないので、少し途方に暮れています。
私の新しい質問は、誓いの中でhttp libを使用するときにエラー引数が必要なのはなぜですか?