Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I unit test client-side jQuery/JavaScript code inside ASP.NET MVC?

Microsoft has really been pushing ASP.NET MVC, and one of its major strengths over ASP.NET Web Forms is unit testing. Then, they announced that they would support jQuery as their official client-side library for the platform, automatically including the source in new projects. Recently, they announced their first official contributions to the jQuery stack: templating, data linking, and globalization.

With this push to more and more client-side logic, how does Microsoft expect developers to unit test with the same power and flexibility that they offer through MVC?

Is there a unit testing framework for client-side scripting that even comes close to comparing to what is available through ASP.NET MVC? Does Microsoft endorse or offer a specific framework that provides this functionality?

like image 830
ChessWhiz Avatar asked Oct 05 '10 16:10

ChessWhiz


2 Answers

You could take a look at QUnit. I am not sure whether it's or it will be endorsed by Microsoft, but it's what's used to unit test the jQuery framework itself.

like image 52
Darin Dimitrov Avatar answered Oct 20 '22 06:10

Darin Dimitrov


I use the following frameworks for JavaScript unit testing:

QUnit

As for me, it is the best choice if you want test your jQuery functions logic. It was developed by the jQuery developers and works with it well.

Jasmine

This is a BDD framework. It is very useful when you write your tests as specifications for your application.

Both frameworks can be integrated in the test explorer of the Visual Studio 2012 using Chutzpah Test Adapter for Visual Studio 2012.

like image 31
Nick Lototskiy Avatar answered Oct 20 '22 05:10

Nick Lototskiy