Mocha + Chai
Sample from slack
by ozzymcduff
HTML
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.3.4/mocha.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.3.4/mocha.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/3.4.1/chai.js"></script>
<div id="mocha"></div>
JavaScript
mocha.setup('bdd');
var expect = chai.expect;
describe('Decimal && Numbers tests', () => {
it('can evaluate expressions', () => {
expect(Math.round(1.5)).to.equal(2)
expect(Math.round(1.2)).to.equal(1)
expect(Math.round(1.8)).to.equal(2)
expect(Math.round(1.9)).to.equal(2)
})
it('should retun correct result type parseInt', () => {
expect(parseInt(50)).to.equal(50)
expect(parseInt('50')).to.equal(50)
expect(parseInt('10,0050.00')).to.equal(10)
expect(parseInt('100050.00')).to.equal(100050)
expect(parseInt('10.0050.00')).to.equal(10)
expect(parseInt(null)).to.be.NaN
expect(parseInt('50 kr')).to.equal(50)
})
it('should retun correct result using Number', () => {
expect(Number(50)).to.equal(50)
expect(Number('50')).to.equal(50)
expect(Number(null)).to.equal(0)
expect(Number('50 kr')).to.be.NaN
})
it('should retun correct result using parseFloat', () => {
expect(parseFloat(0.1) + parseFloat(0.1)).to.equal(0.2)
expect(parseFloat(-0.1) + parseFloat(-0.1)).to.equal(-0.2)
expect(parseFloat(0.1) + parseFloat(0.3)).to.equal(0.4)
expect(parseFloat(0.2) + parseFloat(-0.1)).to.equal(0.1)
expect(0.1 + -0.1).to.equal(0.0)
expect(0.1 + 0.1).to.equal(0.2)
expect(parseFloat(10.0)).to.equal(10)
expect(parseFloat(1.0)).to.equal(1)
})
})
mocha.run();