Mocha Chai Expect

by wangtn18

HTML

<link rel="stylesheet" href="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.css">
<script src="https://cdn.rawgit.com/Automattic/expect.js/0.3.1/index.js"></script>
<script src="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/3.3.0/chai.min.js"></script>
<!-- Mocha test output goes here. -->
<div id="mocha"></div>

JavaScript

mocha.setup('bdd');
var expect = chai.expect;
//Viêt 1 function kiểm tra số lương kí tự 'p' và 't' của 1 chuỗi có bằng nhau hay không
//=============================
//input : string
//output : true or false
//=============================

function equal_pt(str){ 
 var newStr= str.split('');
	console.log(newStr);
	var num1=0;
	var num2=0;
	for (var char of newStr){
  	if (char == 'p'){
    	num1++;
  	} else if( char == 't'){
    	num2++;
  		}
	}	
		if( str == ''){
			return 'empty string' ;
		}else if (str != '') {
			if ( num1 != num2 ) {
				return false;
		}	else if (num1 == num2) {return true}
}
}

describe('equal_pt', function () {
	it('Check if not the string', function () {
    expect(equal_pt('')).to.equal('empty string');
  });
  it('Check if a given string "paatpsts" ', function () {
    expect(equal_pt('paatpsts')).to.equal(true);
  });
  it('Check if a given string "aass"', function () {
    expect(equal_pt('aass')).to.equal(true);
  });
  	it('Check if a given string "paatpss" ', function () {
    expect(equal_pt('paatpss')).to.equal(false);
  });
  
});

mocha.run();