TDD for Javascript developers

50 %
50 %
Information about TDD for Javascript developers

Published on February 19, 2014

Author: andreykucherenko



Introdution to TDD for javascript developers and teams

TDD for JavaScript developers

What is TDD? ● ● ● ● ● TODO list (navigation map) Test first Assert first Fail first Continuous integration

Red > Green > Refactor

What about TDD? ● ● ● ● ● ● ● Unit tests coverage Increases assurance of correctness More complete explorations of requirements Improved code Code as documentation Safe refactoring No extra code

Pair programming

Baby steps

Emergency design

Broken Window Theory

Build Breakers

How to start with TDD? ● ● ● ● ● ● ● Trainings Management support Skills sharing Perseverance Mentors Metrics Coding dojo

How to start with TDD? ● Start new project with TDD/BDD practice ● Start new task with unit tests ● Start to fix bugs with unit tests

Where is my test? ● Developers ● CI ● Deployment

Behavior-driven Development ● Given ... ● When ... ● Then ... ● describe ... ● it ...

JavaScript programming

Tools for JavaScript Runners: ● ● ● ● jsTestDriver PhantomJS Node.js Browser

Tasks for JavaScript ● gruntjs ● grunt plugins

Tasks for JavaScript ● gulp.js

Bootstrap project ● Yeoman ●

Package managers ● npmjs ● ● volojs

Tools for JavaScript IDE: ● ● ● ● ● WebStorm Netbeans Eclipse Sublime Text

Tools for JavaScript Continuous integration: ● ● ● ● Jenkins/Hudson TeamCity Cruise Control Travis-ci

Tools for JavaScript Code analyze: ● ● ● ● jslint jshint JSCoverage jscpd

Tests ● ● ● ● ● ● ● mocha chai buster.js nodeunit qunit jasmine sinon.js

Tests cucumber.js

Mocha - getting started <div id="mocha"></div> ... include js ... <script src="mocha.js"></script> <script>mocha.setup('bdd')</script> ... include tests ... <script> mocha.checkLeaks(); mocha.globals(['jQuery']);; </script>

Mocha - suites and cases describe("Test Suite", function() { it("test case/spec", function() { //BDD style }); }); suite('Test Suite', function(){ test('test case', function(){ //TDD style }); });

Mocha - setUp and tearDown beforeEach(function() { //code here call every time at start of test }); afterEach(function() { //code here call every time at after test });

Mocha - docs

Chai - assert var assert = require('chai').assert , foo = 'bar' , beverages = { tea: [ 'chai', 'matcha', 'oolong' ] }; assert.typeOf(foo, 'string', 'foo is a string'); assert.equal(foo, 'bar', 'foo equal `bar`'); assert.notEqual(foo, 'barz', 'foo not equal `barz`'); assert.lengthOf(foo, 3, 'foo`s value has a length of 3'); assert.lengthOf(beverages.tea, 3, 'beverages has 3 types of tea');

Chai - expect var expect = require('chai').expect , foo = 'bar' , beverages = { tea: [ 'chai', 'matcha', 'oolong' ] }; expect(foo)'string'); expect(foo).to.equal('bar'); expect(foo).to.not.equal('barz'); expect(foo).to.have.length(3); expect(beverages)'tea').with.length(3);

Chai - should var should = require('chai').should() //actually call the the function , foo = 'bar' , beverages = { tea: [ 'chai', 'matcha', 'oolong' ] };'string'); foo.should.equal('bar'); foo.should.not.equal('barz'); foo.should.have.length(3);'tea').with.length(3);

Chai - docs

Sinon.js - spy, stub "test should call subscribers on publish": function () { var callback = sinon.spy(); PubSub.subscribe("message", callback); PubSub.publishSync("message"); assertTrue(callback.called); }

Sinon.js - env var env, $ajax; beforeEach(function() { env = sinon.sandbox.create(); //stub all requests to server $ajax = env.stub($, 'ajax'); }); afterEach(function() { env.restore(); });

Sinon.js - env http://sinonjs. org/docs/

Links & books


Lets write code!

Add a comment

Related presentations

Related pages

JavaScript Test Driven Development with JsUnit and JSMock

This article is a crash course in writing maintainable JavaScript. We'll add features to a running example by iteratively following a simple ...
Read more

Test Driven Development for JavaScript: jQuery and QUnit

Unit test your jQuery code at development time to reduce bugs in your JavaScript application. The QUnit JavaScript TDD framework makes it easy.
Read more

Test-Driven JavaScript Development, The Book

Code and resources for the Addison-Wesley book Test-Driven JavaScript Development by Christian Johansen
Read more

Senior JavaScript Developer with TDD - EPAM | Software ...

Our offices are digital laboratories. Our clients are major global brands. We’re always looking for talented teammates. Think you’ve got what it takes?
Read more

Test-Driven JavaScript Development in Practice

TDD is an iterative development process where each iteration starts by writing a test which forms a part of the specification we are implementing.
Read more

Test-Driven JavaScript Development (Developer's Library ...

Buy Test-Driven JavaScript Development (Developer's Library) on FREE SHIPPING on qualified orders
Read more

Test-Driven JavaScript Development | InformIT

For JavaScript developers working on increasingly large and complex projects, effective automated testing is crucial to success. Test-Driven JavaScript ...
Read more

Let’s Code: Test-Driven JavaScript

James Shore presents a fascinating screencast on rigorous, professional JavaScript development Watch Now ... I’m completely new to TDD and this is by far
Read more

Using Test Driven Development with React.js to Add Multi ...

Using Test Driven Development with React.js to Add Multi ... we will be using Test Driven Development TDD to enhance ... especially for JavaScript ...
Read more