Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let mod=require('../math');
  2. const chai=require('chai');
  3. const sinon=require('sinon')
  4.  
  5.  
  6.  
  7. //Testing doDivision
  8. describe('doDivision(a,b)', function () {
  9.     it('Should return correct result', function () {
  10.       a=5;
  11.       b=6;
  12.       var div=mod.doDivision(a,b).toFixed(2);
  13.       chai.expect(div).to.equal((a/b).toFixed(2));
  14.     });
  15.  
  16.  
  17. });
  18.  
  19. //Fail case dividing by string
  20. describe('doDivision(a,b)', function () {
  21.   it('Should return error when wrong type is inserted', function () {
  22.     chai.expect(function() { doDivision(4/'4'); }).to.throw(Error);
  23.   });
  24.  
  25. });
  26.  
  27.  
  28.  
  29. //Corner case dividing by infinity
  30. describe('doDivision(a,b)', function () {
  31.   it('dividing by infinity should be zero', function () {
  32.     var bang=mod.doDivision(4,Infinity);
  33.     chai.expect(bang).to.equal(0);
  34.   });
  35.  
  36.  
  37. });
  38.  
  39. //part 2 stringifydivision test
  40.  
  41. describe('stringifyDivision(a,b)', function () {
  42.   beforeEach(() => {
  43.     var a=4
  44.     var b=5
  45.     var divisionFake=sinon.fake.returns(a/b);
  46.     sinon.replace(mod, 'doDivision',divisionFake);
  47.   });
  48.     it('Should return correct result', function () {
  49.       a=4;
  50.       b=5;
  51.       var sDivision=mod.stringifyDivision(a,b);
  52.       chai.expect(sDivision).to.equal(a+' '+'divided by'+' '+b+' '+ 'is'+' '+a/b);
  53.     });
  54.  
  55.   });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement