Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let mod=require('../math');
- const chai=require('chai');
- const sinon=require('sinon')
- //Testing doDivision
- describe('doDivision(a,b)', function () {
- it('Should return correct result', function () {
- a=5;
- b=6;
- var div=mod.doDivision(a,b).toFixed(2);
- chai.expect(div).to.equal((a/b).toFixed(2));
- });
- });
- //Fail case dividing by string
- describe('doDivision(a,b)', function () {
- it('Should return error when wrong type is inserted', function () {
- chai.expect(function() { doDivision(4/'4'); }).to.throw(Error);
- });
- });
- //Corner case dividing by infinity
- describe('doDivision(a,b)', function () {
- it('dividing by infinity should be zero', function () {
- var bang=mod.doDivision(4,Infinity);
- chai.expect(bang).to.equal(0);
- });
- });
- //part 2 stringifydivision test
- describe('stringifyDivision(a,b)', function () {
- beforeEach(() => {
- var a=4
- var b=5
- var divisionFake=sinon.fake.returns(a/b);
- sinon.replace(mod, 'doDivision',divisionFake);
- });
- it('Should return correct result', function () {
- a=4;
- b=5;
- var sDivision=mod.stringifyDivision(a,b);
- chai.expect(sDivision).to.equal(a+' '+'divided by'+' '+b+' '+ 'is'+' '+a/b);
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement