简体   繁体   中英

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.

       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. 2. WriteConsoleLog(exception) : Writes an exception Console.Error/Console.Warn/Console.Log,depending upon errortype passed by user.

Now I wanna have a unit test cases for LogError,LogWarn,LogInfo function using Qunit framework.

Could somebody provide me a suggestion how to start and how to go about.

Regards, 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). You could use something like Mockjax for that.

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. http://api.qunitjs.com/asyncTest/

(PS Sorry if my formatting is bad, typing this on my phone.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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