Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using jquery and HTML 5 techniques (like File API, HistoryAPI) extensively in a project I am working on.

I was wondering what tools I can use for

  1. quality assurance my javascript and front end code
  2. unit testing my javascript and front end code

Let me share some background info.

If somebody asked me about this for PHP, I would say, use PHPUnit for writing unit tests, use PHP CodeSniffer and then with the help of Phing and Jenkins, put this all into a single build process.

I basically want to know if something similar can be pulled off with javascript using Jenkins.

Do share your actual experiences. Please advise me on the most beginner-friendly ones.

Disclosure: I cross-posted in G+ community for javascript and HTML5.

share|improve this question

closed as not constructive by gnat, Walter, Glenn Nelson, Dynamic, ChrisF Dec 30 '12 at 13:51

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

QUnit, jshint and jenkins. Go. – Florian Margaine Dec 29 '12 at 11:34

Two methods spring to mind (based on experience):

  1. QUnit, originally developed for jQuery and released as a seperate tool in 2008. It has similar semantics than many other unit testing frameworks. This is good for unit testing JavaScript code, as you state.

  2. Selenium. This is great for unit and integration testing of web pages and maybe handy if your JS code relies on a web browser/DOM to be present.

Both tools can be made to work from a command line, so it should be easily possible to integrate in a Jenkins build.

share|improve this answer
Thank you for the suggestions. My javascript code is more for stuff like: a) when hover over something, something happens. b) when drag n drop, something happens. For code like these, how do I write such unit tests? – Kim Stacks Dec 29 '12 at 12:54
Well what you want to do is use QUnit or Jasmine to test the various functions or methods in your code, that will get the various parts of your code working correctly. Then you use Selenium to do end to end tests. The problem is that Selenium tests can be rather slow so you want to do as much as possible with unit tests – Zachary K Dec 29 '12 at 17:51

As a beginner, I would suggest you use the web service for JSHint, This is a linter for your JavaScript code, which will help you write your code in an efficient way.

As a tip, you may get a few 'not defined' warnings. These would be globals such as jQuery ($) or console.

You can turn these off my placing at the top of your script,

/*global "$"*/
/*global "console"*/

Just repeat this pattern for whatever global you would like JSHint to ignore.

As for the Unit Testing, I don't see much point in writing tests for hover and drop events. Although this is my opinion. For something like that I would monitor performance with the Chrome WebTools, in which I doubt there would be any damage caused if you keep your code efficient.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.