Nodeunit testing event based async code

做~自己de王妃 提交于 2019-12-06 15:28:46

The problem ended up being that the event listeners setup weren't being destroyed between tests. I fixed the issue by modifying the setUp function to use proxyquire with the noPreserveCache flag set:

var proxyquire = require( 'proxyquire' );
...

setUp: function ( callback ) {
  this.app = {};
  proxyquire.noPreserveCache();
  var async_setup = proxyquire( '../async_setup', {} );
  async_setup( this.app, callback );
}

The error message in Webstorm had more info, with a stack trace to a nodeunit async module error:

iterator(x.value, function (err, v) {
Cannot read property 'value' of undefined

When I stepped through the code I noticed that there were two event listeners setup even though I only set one in the test.

Hope this helps someone else out there.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!