Javascript Unit Test

https://qunitjs.com/
http://unitjs.com/
https://www.sitepoint.com/javascript-testing-unit-functional-integration/
https://facebook.github.io/jest/
https://medium.com/javascript-scene/what-every-unit-test-needs-f6cd34d9836d#.ov7gpgr2d
http://designmodo.com/test-javascript-unit/
https://www.infoq.com/research/javascript-unit-testing

http://www.netmagazine.com/features/essential-javascript-top-five-testing-libraries
http://msdn.microsoft.com/en-us/scriptjunkie/gg655487.aspx - Unit Testing 101: Are You Testing Your JavaScript?
http://msdn.microsoft.com/en-us/scriptjunkie/gg650426.aspx - Test Driven Development: Top-Down or Bottom-Up?
http://msdn.microsoft.com/en-us/scriptjunkie/gg749824.aspx - Automating JavaScript Testing with QUnit
http://www.sitepoint.com/blogs/2010/08/28/simultaneous-multiple-browser-javascript-testing-with-yeti/
http://net.tutsplus.com/tutorials/javascript-ajax/quick-tip-quick-and-easy-javascript-testing-with-assert/
http://net.tutsplus.com/tutorials/javascript-ajax/how-to-test-your-javascript-code-with-qunit/
http://net.tutsplus.com/tutorials/javascript-ajax/test-driven-javascript-development-in-practice/

Mocks Aren't Stubs
Dependency Injection
http://tinnedfruit.com/2011/02/14/jasmine-matchers-for-sinonjs.html
http://tinnedfruit.com/2011/03/03/testing-backbone-apps-with-jasmine-sinon.html
http://tinnedfruit.com/2011/03/25/testing-backbone-apps-with-jasmine-sinon-2.html
http://tinnedfruit.com/2011/04/26/testing-backbone-apps-with-jasmine-sinon-3.html
http://net.tutsplus.com/tutorials/javascript-ajax/testing-javascript-with-phantomjs
http://net.tutsplus.com/tutorials/javascript-ajax/better-coffeescript-testing-with-mocha/
http://coding.smashingmagazine.com/2012/06/27/introduction-to-javascript-unit-testing/
http://www.infoq.com/news/2012/07/javascript-test-vs
http://www.readmore.ch/post/18940470535
http://www.slideshare.net/emwendelin/javascript-ci
http://pivotal.github.com/jasmine/
http://www.zachleat.com/web/javascript-tdd-winner/
JSUnit
PhantomJS
http://net.tutsplus.com/tutorials/javascript-ajax/testing-javascript-with-phantomjs/
http://www.slideshare.net/napcs/testing-clientside-code-with-jasmine-and-coffeescript
http://net.tutsplus.com/tutorials/javascript-ajax/make-javascript-testing-fun-with-testem/
http://net.tutsplus.com/tutorials/javascript-ajax/meet-crockford%E2%80%99s-jscheck/
http://net.tutsplus.com/tutorials/javascript-ajax/test-driven-javascript-development-in-practice/
http://net.tutsplus.com/tutorials/javascript-ajax/testing-your-javascript-with-jasmine/
http://net.tutsplus.com/tutorials/javascript-ajax/quick-tip-quick-and-easy-javascript-testing-with-assert/
http://net.tutsplus.com/tutorials/javascript-ajax/how-to-test-your-javascript-code-with-qunit/
http://visionmedia.github.com/mocha/
http://phantomjs.org/
http://jscomplexity.org/
http://blanketjs.org/
http://gotwarlost.github.io/istanbul/
http://programming.oreilly.com/2013/05/end-to-end-javascript-quality-analysis.html

To test a piece of code, you must be willing to separate the code from its surrounding, and also from things it depends on.

If a method is going to do some UI operation (or some other complicated operation), it is not useful to check the result of that operation. It is more important to see if your code asked for that operation to be performed. If we approach writing the test code from that point of view, it becomes easier to test the code. We can also entirely remove the UI from testing by using Mock objects. JavaScript is a dynamic language that makes it easy to mock.

var setFocusCalled = false;
function dummySetFocus() { setFocusCalled = true; }

var originalSetFocus = setFocus;
setFocus = dummySetFocus;
...
setFocus = originalSetFocus
assertTrue(setFocusCalled);

JsUnit
YUI Test
JsSpec
JsSpec #2
QUnit
jsUnity

JSMock
Mockito
MockMe
Sinon.JS

We can stub out the server, and we can write tests to test our javascript code as long as our code does not cause the browser to go to another page. If our code cause the browser to go to another page, can we some stub out that page too?

Selenium limitation seems to be that it rely on when the onload handler to load itself. It seems that selenium should be a browser plugin for IE instead of HTA. If we use Selenium IDE testrunner mode, can we somehow cause Selenium IDE to always load selenium core ahead of other script?

A JavaScript function that involves both logic and DOM manipulation and event should be separated into 2 parts, one contains logic, one contains DOM manipulation and event. The part that contains logic can be tested easily. The part that contains DOM manipulation and event can also be tested using mocks, and stubs.

JsUnit
jsTest
CrossCheck
jqUnit

Test Driven Development: Top-Down or Bottom-Up?
Unit Testing 101: Are You Testing Your JavaScript?
JavaScript Test Driven Development with JsUnit and JSMock

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License