Setting up QunitJs for Asp.net MVC Debugging

    Using QUnit is important for me on some of my projects that are more front-end driven. So developing, debugging and testing all need to happen in javascript but without being in the final production. One thing I do not want to do is include the QunitJs in my bundles and would serve no purpose because the bundling and minifying does not happen for debugging. Instead what I did was create an extension method and return a bool, like the one shown in the resources.
//Location ../Helpers/IsDebugging
public static bool IsDebugging(this HtmlHelper helper)
{
  #if DEBUG
      return true;
  #else
      return false;
  #endif
}
//Location ../Views/Shared/_Layout.cshtml
//These two files are not apart of any bundled packages.

@if(Html.IsReleaseBuild()) {
    @Scripts.Render("~/Scripts/qunit-1.14.0.js")
    @Styles.Render("~/Content/qunit-1.14.0.css")
}
Side Notes
The intellisense will do some weird things with the coloring for code inside the else statement but it will have no impact on the results and you can simply ignore it.
I didn't use the following  property because it caused performance issue when I started up the app as it is also noted in the resources.
HttpContext.Current.IsDebuggingEnabled
Resources
C# and ASP.NET MVC: Using #if directive in a view - Stack Overflow - Most of the solution here.
ASP.NET IsDebuggingEnabled - Using this had performance issues for me.
Bundling and Minification : The Official Microsoft ASP.NET Site
JavaScript unit test tools for TDD - Stack Overflow - In case you're not using Jquery for development.

Popular posts from this blog

Nginx Best Practices Extended

Installing Windows on Acer chromebook 15 cb3-532

Entity Framework: ToListAynsc & WhereAsync