Telerik blogs

With every new release of JustCode we at Telerik are committed to providing you with the best tool for writing better, faster and error free code with ease. That of course includes testing it. With the latest and greatest version of JustCode we added support for two of the widely and most commonly used JavaScript testing frameworks out there - Jasmine and QUnit.

In this post we will cover the support for Jasmine BDD JavaScript tests in JustCode.

Industry first Jasmine support

Jasmine is a behavior-driven development framework for testing your JavaScript code. For more information and details about the framework please visit Jasmine official site.

JustCode is the first and only tool on the market today that can analyze, show and run your Jasmine tests, no hassles, no configuration or setup, it just works. What it takes to start running Jasmine tests right from within Visual Studio is to open a solution with the “jasmine.js” file included in it.

 

JustCode will analyze the whole solution and will display all Jasmine tests in the test runner window alongside any other tests you may have. Nested jasmine suites are supported as well.

 

You can expect all things that work for other test frameworks and languages to work here as well - filtering, grouping, and navigation.

Notice how JustCode shows you the ignored jasmine tests or suites in gray. (Ignoring in Jasmine works by renaming the JavaScript function from it to xit and describe to xdescribe for suites)

Just hit “Run” for the Fun

Typically to run Jasmine tests you are required to create an html page that includes all required JavaScript files like jasmine.js, jasmine.css, js files that contain you tests. This is not needed when you use JustCode, but is supported as we will see later.

To run your Jasmine tests in JustCode all you need to do is hit “Run” and JustCode will generate the required html test page and will populate it with everything it knows about your tests so they can be run successfully without any additional manual work. JustCode will start Internet Explorer browser, execute your Jasmine tests and show you the results.

 There is even an option for showing the browser running the tests if you wish so. (JustCode->Options->Unit Testing):

References

Visual Studio helps you a lot when writing JavaScript code by showing IntelliSense for js files you reference using “/// <reference path” tag at the beginning of your js files. (To add a js reference, just drag a js file into the code editor from Solution Explorer)

JustCode supports such references in your JavaScript tests so you can specify which files you want to include in the generated html test file:

Here the PlayerSpec.js file containing the Jasmine specs (tests) for “Player”, reference tags for the Player.js file and additional Song.js file that is required.

You can even include your own version of Jasmine.js or Jasmine-html.js or both, using js references and JustCode will make sure that it uses yours instead of the default Jasmine.js shipped with JustCode

For correct results there are some requirements (for this release though):

  • Visual Studio needs to be elevated (Run as Administrator) so Jasmine tests results are processed correctly
  • Internet Explorer requires Allow active content to run files on My Computer to be checked.

Custom html test pages

In some cases you may want to have a custom page for your Jasmine tests. JustCode supports that as well. Just add an html (or htm) web page with the same name as your jasmine tests file and JustCode will run these tests with your test web page instead of auto-generating one.

Keep in mind that Internet Explorer requires you to use Mark of the Web in the beginning of your page. We want to handle this requirement better in the future versions of JustCode.

What’s next

Currently there is no other product on the market that provides you with such integrated experience for testing your JavaScript with Jasmine BDD framework. We will continue to improve this integration in the future versions of JustCode by addressing:

  • Support for more browsers out of the box (Firefox, Opera, Chrome and others)
  • Remove Visual Studio elevation (Run as administrator) requirement
  • Remove mark of the web requirement
  • Remove the Internet Explorer active content requirement

Happy JavaScript BDD testing with Jasmine and JustCode!

The JustCode team


About the Author

Chris Eargle

is a Microsoft C# MVP with over a decade of experience designing and developing enterprise applications, and he runs the local .NET User Group: the Columbia Enterprise Developers Guild. He is a frequent guest of conferences and community events promoting best practices and new technologies. Chris is a native Carolinian; his family settled the Dutch Form region of South Carolina in 1752. He currently resides in Columbia with his wife, Binyue, his dog, Laika, and his three cats: Meeko, Tigger, and Sookie. Amazingly, they all get along... except for Meeko, who is by no means meek.

Related Posts

Comments

Comments are disabled in preview mode.