Skip to content

Instantly share code, notes, and snippets.

@igorlima
Last active January 1, 2016 05:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save igorlima/8098276 to your computer and use it in GitHub Desktop.
Save igorlima/8098276 to your computer and use it in GitHub Desktop.
Desenvolvimento dirigido a comportamento com JasmineJS

Gittip Donate Button

To install generator-jasmine-node from npm, run:

npm install -g jasmine-node

npm install -g generator-jasmine-node

Finally, initiate the generator:

yo jasmine-node

Automating the Test Suite

From the root of your project, run:

grunt watch

Now any updates you make to your spec or module file will run the test suite.

Generating Additional Modules & Specs

yo jasmine-node:module "moduleName"

Generating Specs

yo jasmine-node:spec "moduleName"

'use strict';
module.exports = (function() {
var Calculadora = {
somar: function() {
var soma = 0, i = undefined;
for( i=0; i < arguments.length; i++ )
soma += arguments[i];
return soma;
},
subtrair: function(numero1, numero2) {
return numero1 - numero2;
},
multiplicar: function() {
var multiplicacao = arguments[0], i = undefined;
for( i=1; i < arguments.length; i++ )
multiplicacao *= arguments[i];
return multiplicacao;
},
dividir: function(numero1, numero2) {
return numero1 / numero2;
}
};
return Calculadora;
})();
'use strict';
describe('Calculadora', function() {
var Calculadora = require('./Calculadora');
describe('Soma', function() {
it('2 + 2 DEVE ser 4', function() {
expect( Calculadora.somar( 2, 2) ).toBe( 4 );
});
it("2 + 2 + 3 + 1 DEVE ser 8", function() {
expect( Calculadora.somar( 2, 2, 3, 1 ) ).toBe( 8 );
});
});
describe('Subtracao', function() {
it("2 - 2 DEVE ser 0", function() {
expect( Calculadora.subtrair(2, 2) ).toBe( 0 );
});
it("3 - 4 DEVE ser -1", function() {
expect( Calculadora.subtrair(3, 4) ).toBe( -1 );
});
});
describe('Multiplicacao', function() {
it("3 multiplicado por 2 DEVE ser 6", function() {
expect( Calculadora.multiplicar(3, 2) ).toBe( 6 );
});
it("3 multiplicado por 2 e em seguida por 4 DEVE ser 24", function() {
expect( Calculadora.multiplicar(3, 2, 4) ).toBe( 24 );
});
});
describe('Divisao', function() {
it("2 dividido por 2 DEVE ser 1", function() {
expect( Calculadora.dividir(2, 2) ).toBe( 1 );
});
it("6 dividido por 2 DEVE ser 3", function() {
expect( Calculadora.dividir(6, 2) ).toBe( 3 );
});
});
});
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-shell');
grunt.initConfig({
watch: {
js: {
files: ['Calculadora.js', 'Calculadora.spec.js'],
tasks: ['test']
}
},
shell: {
test: {
options: { stdout: true },
command: 'jasmine-node Calculadora.spec.js'
}
}
});
grunt.registerTask('test', 'shell:test');
}
{
"name": "your-sweet-unit-test",
"version": "0.0.0",
"dependencies": {
"grunt": "~0.4.1",
"grunt-contrib-watch": "~0.5.3",
"grunt-shell": "~0.5.0",
"jasmine-node" : "1.3.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment