Using JS Fiddle to test JavaScript

If like me you have been developing web apps for a long time, its highly likely you have been in a situation where you need to test some JavaScript that can only be accessed after a process of the app is complete. I had this issue recently with a JQuery Mobile SPA (Single Page Application) where to get to the script I wanted to test required following a process through the app that took around 5 minutes to complete, very tedious!

However, there is a better solution, https://jsfiddle.net/

Jsfiddle is an online tool for testing JavaScript from your browser.

The JavaScript I wanted to test simply updated a URL redirect variable based on current URL. To effectively test I slightly modified the code to spoof the current URL otherwise I would always get the jsfiddle URL, see the section commented out.

 

var IBID = 522;
// needs to be commented or it will return jsfiddle.net
//var Current_URL = window.location.href;
var Current_URL = "staging.tester.dev";
var IB_URL = "";

if (Current_URL.includes(".dev"))
{
	IB_URL = "http://www.intermittentbug.dev/SiteAdmin/EditAuction/Editstep3/##IBID##?test=true";
}
else if (Current_URL.includes("staging"))
{
	IB_URL = "http://staging.intermittentbug.dev/SiteAdmin/EditAuction/Editstep3/##IBID##?test=true";
}
else
{
	IB_URL = "http://www.intermittentbug.com/SiteAdmin/EditAuction/Editstep3/##IBID##?test=true";
}

IB_URL = IB_URL.replace("##IBID##", IBID);
alert(IB_URL);


To test your JavaScript, simple paste your code into the JavaScript box and click run. See screenshots below...



To test your JavaScript, simple paste your code into the JavaScript box and click run.



 This was just a simple example. Using jsfiddle you can test AJAX with JSON, XML and even JSONP.


 


JGilmartin Profile Image

JGilmartin

Technical Architect at Pinewood Technologies

Rating: 2890

C# Expert

Offline


Tutorial Statistics
  • Views: 659
  • Comments: 0
  • Author: JGilmartin (2890)
  • Date: 21/11/2016 22:09
Tags
JavaScript

© 2016 - 2018 - IntermittentBug