1
私は非同期関数を呼び出すnode.jsファイルを持っており、 "then"のプロパティがコンテキストで未定義にならないTypeErrorを取得し続けます。Node.js - > TypeError:コンテキスト 'で未定義のプロパティ'を読み取ることができません
async.js
if (typeof window === 'undefined') {
require('../../app/async');
var expect = require('chai').expect;
}
describe('async behavior', function() {
it('you should understand how to use promises to handle asynchronicity', function(done) {
var flag = false;
var finished = 0;
var total = 2;
function finish(_done) {
if (++finished === total) { _done(); }
}
// This is where the error occurs
asyncAnswers.async(true).then(function(result) {
flag = result;
expect(flag).to.eql(true);
finish(done);
});
asyncAnswers.async('success').then(function(result) {
flag = result;
expect(flag).to.eql('success');
finish(done);
});
expect(flag).to.eql(false);
});
exports = typeof window === 'undefined' ? global : window;
exports.asyncAnswers = {
async: function(value) {
},
manipulateRemoteData: function(url) {
}
};
非同期アプリ/任意の助けいただければ幸いです!
この場合、どのようなプロミスオブジェクトを返す必要がありますか? –
プロミスは、基本的には非同期操作のラッパーです。それらの詳細については、https://developers.google.com/web/fundamentals/getting-started/primers/promisesをご覧ください。それらを読んだら、自分でこの質問に答えることができるかどうかを見てください。 – thirtyseven
適切な約束オブジェクトを渡すことができないので、このコードを正しく実行するにはまだ問題があります。 –