大佬教程收集整理的这篇文章主要介绍了单元测试 – node.js:以一种方式导出文件中的所有功能(例如,启用单元测试)的任何方法,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我知道我可以手动导出每个功能,如:
exports.MyFunction = MyFunction;
但是我想知道是否有更简单/更轻松的方式来做到这一点。
(是的,我意识到出于模块化的原因,导出所有功能并不总是一个好主意,但是对于单元测试,您希望看到所有的小功能,以便您可以逐个测试。)
谢谢!
// save this into a variable,so it can be used reliably in other contexts var self = this; // the scope of the file is the `exports` object,so `this === self === exports` self.fnName = function () { ... } // call it the same way self.fnName();
或这个:
// You can declare your exported functions here var file = module.exports = { fn1: function () { // do stuff... },fn2: function () { // do stuff... } } // and use them like this in the file as well file.fn1();
或这个:
// each function is declared like this. Have to watch for typeos,as we're typing fnName twice fnName = exports.fnName = function () { ... } // Now you can use them as file-scoped functions,rather than as properties of an object fnName();
以上是大佬教程为你收集整理的单元测试 – node.js:以一种方式导出文件中的所有功能(例如,启用单元测试)的任何方法全部内容,希望文章能够帮你解决单元测试 – node.js:以一种方式导出文件中的所有功能(例如,启用单元测试)的任何方法所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。