0
私はこれについて他の質問を見ましたが、同じ問題を抱えているようには見えません。Sinon FakeXMLHttpRequest TypeError: '未定義'はオブジェクトではありません(this.requests [0] 'を評価する)
beforeEach(function() {
this.xhr = sinon.useFakeXMLHttpRequest();
var requests = this.requests = [];
this.xhr.onCreate = function (xhr) {
requests.push(xhr);
}.bind(this);
});
afterEach(function() {
this.xhr.restore();
});
this.requests[0].respond(500, { 'content-Type': 'application/json'},
'[{ "Response": "500 error text", "ResponseText": "This was the first thing we expected to happen"}]');
これはFakeXMLHttpRequestを使用した場合sinonのドキュメントにあるものと一致しているようだが、それは常に
TypeError例外を示すエラーを返します:「未定義の」が「this.requestsを評価するオブジェクト([0ではありません] ')
なぜ私が見たすべての例に比べて重要なものが欠けているようには見えないのか分かりません。
はsinon.useFakeXMLHttpRequestはsignon.useFakeXMLHttpRequestであるはずですか? – Cameron637
私はそうは思わない。 Sinonのドキュメントには「sinon」という文字が含まれています http://sinonjs.org/docs/#useFakeXMLHttpRequest –
ああ、そのことはわかりませんでした。 – Cameron637