简体   繁体   English

Qunit Javascript客户端日志记录

[英]Qunit Javascript client logging

we have small wrapper client logging framework to enable javascript client logging.We have exposed different function like LogError,LogWarn,LogInfo in Javascript. 我们有一个小型包装的客户端日志记录框架来启用javascript客户端日志记录。我们在Javascript中公开了LogError,LogWarn,LogInfo等不同功能。

       JavaScriptLogger.LogError(exception)            
       {
         postAjax(exception);
         WriteConsoleLog(exception)

   }

When ever user logs a error using JavaScriptLogger.LogError(exception),two things get executed: 1. postAjax(exception) : An ajax post is made to specified server URL. 每当用户使用JavaScriptLogger.LogError(exception)记录错误时,都会执行两件事:1. postAjax(exception):对指定的服务器URL进行ajax发布。 2. WriteConsoleLog(exception) : Writes an exception Console.Error/Console.Warn/Console.Log,depending upon errortype passed by user. 2. WriteConsoleLog(exception):根据用户传递的错误类型,编写一个例外Console.Error / Console.Warn / Console.Log。

Now I wanna have a unit test cases for LogError,LogWarn,LogInfo function using Qunit framework. 现在,我想使用Qunit框架针对LogError,LogWarn,LogInfo函数进行单元测试。

Could somebody provide me a suggestion how to start and how to go about. 有人可以给我一个建议如何开始和如何进行。

Regards, SCP 关于SCP

Well, first off, I hope you understand that someone could flood your server logs this way, and hopefully you have something in place to prevent this. 好吧,首先,我希望您了解有人可以以此方式泛滥您的服务器日志,并希望您已采取适当措施来防止这种情况。

Second, you would want to mock that Ajax call so that you aren't relying on your server to work (eliminating one source of potential errors). 其次,您将希望模拟该Ajax调用,以便您不依赖服务器工作(消除了潜在错误的一种来源)。 You could use something like Mockjax for that. 您可以为此使用Mockjax之类的东西。

After that, you would want to probably run all of those tests in an asyncTest call (versus a simple test ) since the Ajax call is still supposed to be asynchronous. 在那之后,您可能希望在asyncTest调用中运行所有这些测试(相对于简单的test ),因为Ajax调用仍然应该是异步的。 http://api.qunitjs.com/asyncTest/ http://api.qunitjs.com/asyncTest/

(PS Sorry if my formatting is bad, typing this on my phone.) (PS抱歉,如果我的格式化不正确,请在手机上键入。)

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

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