Node.js – > TypeError:无法读取上下文未定义的属性'then'

我有一个node.js文件调用一个asynchronous函数,我不断得到一个TypeError,其中“then”的属性不能在上下文中未定义。

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); }); 

应用程序/asynchronous

 exports = typeof window === 'undefined' ? global : window; exports.asyncAnswers = { async: function(value) { }, manipulateRemoteData: function(url) { } }; 

任何帮助将不胜感激!

你在app/async async函数需要返回一个Promise对象。 现在,它没有返回任何东西。