简体   繁体   English

Javascript Mocha Tests-在函数表达式中测试函数表达式

[英]Javascript Mocha Tests - Testing function expressions inside function expressions

I haven't used Mocha before, so I am a real novice when it comes to testing. 我以前没有使用过Mocha,因此在测试方面我是一个真正的新手。 However, I wanted to know if it's possible to test a function expression inside of a function expression? 但是,我想知道是否可以在函数表达式内部测试函数表达式? I know there are other posts on how you cannot access function expressions inside function declarations and so on. 我知道还有其他关于如何无法访问函数声明内的函数表达式的文章。

So, is it possible to access function expressions inside function expressions and test with Mocha? 那么,是否可以在函数表达式内部访问函数表达式并使用Mocha进行测试? For example, I have the following code: 例如,我有以下代码:

var masterFunction = function() {

       var siGogglin = functionDeclaration(putSomethingHere);

       function functionDeclaration(code) {
           var yoyo = [];

           //some stuff I don't want you to see 

           return yoyo;
       };
};

Is it possible to test the function functionDeclaration from the variable siGogglin within masterFunction ? 是否有可能测试功能functionDeclaration从变量siGogglinmasterFunction If so, could you give me an example of how it could be done? 如果是这样,您能否举一个例子说明如何完成?

Thanks. 谢谢。

我的回答是“否”,因为您实际上是在masterFunction内创建了一个私有函数,除非向原型添加getter方法,否则该私有函数不应在masterFunction范围之外进行访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM