Derik Whittaker

Syndication

News


Setting up Unit Testing w/ Jasmine, Chutzpah and Typescript

Recently I got back into writing html/javascript code as part of my day job and boy-o-boy have things changed since the last time i did any of this.  One thing that has not changed for me however was my belief in unit testing, so it was very painful for me to be writing hundreds of lines of javascript (ok really TypeScript) code with NO tests supporting them.  At first I was able to live with this feeling because I was too busy trying to relearn how to do javascript development.  However, I have not reached a comfort level where the lack of tests is killing me again.

No of course in client/server land of .Net development getting started testing is dead simple, however in the Javascript/html world things are still in the toddler stage, IMO, and there are many, many options to testing and I had no idea which is the best.  After doing some searching and asking on twitter I settled on Jasmine as my test runner. 

Now that I picked Jasmine, how did I get started?  Here is what I did (this post is a merging of many, many posts I looked at to get me pointed in the right direction)

Step 1: Create a new test project

Open up Visual Studio 2012 and create a basic MVC 4 application (empty)

Step 2: Get Jasmine

Install the Jasmine NuGet Package
image

Step 3: Run your application in order to validate that jasmine is running correctly

image

Yup, we are good

Step 4: Get Chutzpah

I wanted a way to run my tests inside of Visual Studio and this plugin seemed to do the trick. I opted to install the test adapter which can be found here

Step 5: Validate that Chutzpah adapter was setup correctly

image

As you can see from above, it is setup correctly.

Now I wanted to be able to author my tests in Typescript and have them run as well.

Step 6: Download the Jasmine typescript definition file.  I put this inside my scripts folder as seen below

image

Step 7: Create my Test Spec

The trick to getting this to work of course is that I need to include the jasmine-1.2.d.ts definition file inside my .ts file as below

image

I also need to reference my class under test file inside my .ts file as below

image

Once I did both of these I could write my first test as below

image 

Bam, now I have a jasmine test written via Typescript and runnable via the Chutzpah test running.  Of course I am sure there are other ways to get this to work, this is just what worked for me.

Till next time,


Posted 12-23-2012 6:49 AM by Derik Whittaker
Filed under: , , ,

[Advertisement]

Comments

buy viagra online wrote re: Setting up Unit Testing w/ Jasmine, Chutzpah and Typescript
on 02-03-2013 12:17 AM

S9skMj Wow, great article. Keep writing.

buy viagra online wrote re: Setting up Unit Testing w/ Jasmine, Chutzpah and Typescript
on 02-03-2013 5:24 AM

9Lq3c3 I value the article post.Really looking forward to read more. Great.

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)