Executar mocha Unit Tests

Posted Over 9 years ago. Visible to the public.

Atualmente o projeto DashBoards utiliza o mocha.js para executar os testes de unidade. Documentação Show archive.org snapshot .

Para rodar os testes faz-se necessária a instalação do mocha.js via npm, no projeto Dashboards existe o package.json que define a dependência, porém caso vá utilizar em outro projeto execute:

npm install -g mocha

Exemplo de teste:

//File /test/unit/js/numberUtilsUnitTest.js
describe('NumberUtils', function () {
	var units = ['K', 'M', 'Bi' , 'Tri' , 'P' , 'E'];

	it("Numbers in the billions should format correctly whitout scale", function () {
		var oneBillion = 1000000000;
		var oneBilhonAndOneHundredMillion = 1010000000;
		testIntervalFormatNumberWithSufix(oneBillion, oneBilhonAndOneHundredMillion, 475, 'Bi');
	});

	var testIntervalFormatNumberWithSufix = function (begin, end, jumpNumber, sufix, scale) {
		for (var i = begin; i <= end; i = i + jumpNumber) {
			var numberFormatted = i.humanFriendlyNumber(2, units, scale)
			assert(numberFormatted.indexOf(sufix) != -1);
		}
	}
});

Para executar o teste basta executar : mocha test/unit/js/numberUtilsUnitTest.js

E o retorno será:
^
NumberUtils
✓ Numbers in the billions should format correctly whitout scale (75ms)
1 passing (75ms)

Lembrando que para executar tem que ter o node.js + npm instalados na máquina

kaio cristian
Last edit
Over 9 years ago
Posted by kaio cristian to ZeroGlosa (2014-09-29 18:08)