Advertisement
MartinGeorgiev

Unit test

Mar 13th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe("HolidayPackage Test", function() {
  2.     let sampleInstance;
  3.     beforeEach(function(){
  4.         sampleInstance = new HolidayPackage("Hawaii","Winter");
  5.     });
  6.     it('testing constructor destiantion property', function() {
  7.         expect(sampleInstance.destination).to.deep.equal('Hawaii');
  8.     });
  9.     it('testing constructor season property', function() {
  10.         expect(sampleInstance.season).to.deep.equal('Winter');
  11.     });
  12.     it('testing constructor insuranceIncluded property', function() {
  13.         expect(sampleInstance.insuranceIncluded).to.deep.equal(false);
  14.     });
  15.     it('testing constructor vacationers property', function() {
  16.         expect(sampleInstance.vacationers).to.deep.equal([]);
  17.     });
  18.     it('testing addVacationer', function() {
  19.         expect(()=>sampleInstance.addVacationer(' ')).to.throw('Vacationer name must be a non-empty string');
  20.     });
  21.  
  22.     it('testing addVacationer with NO string', function() {
  23.         expect(()=>sampleInstance.addVacationer(123123)).to.throw('Vacationer name must be a non-empty string');
  24.     });
  25.  
  26.     it('testing addVacationer to include first and last name', function() {
  27.         expect(()=>sampleInstance.addVacationer('Ivailo')).to.throw('Name must consist of first name and last name');
  28.     });
  29.     it('testing insuranceIncluded with NON boolean', function() {
  30.         expect(()=> sampleInstance.insuranceIncluded = "Pesho").to.throw('Insurance status must be a boolean');
  31.     });
  32.  
  33.     it('testing insuranceIncluded with TRUE boolean', function() {
  34.         sampleInstance.insuranceIncluded = true;
  35.         expect( sampleInstance.insuranceIncluded ).to.equal(true);
  36.     });
  37.  
  38.     it('testing insuranceIncluded with FALSE boolean', function() {
  39.         sampleInstance.insuranceIncluded = false;
  40.         expect( sampleInstance.insuranceIncluded ).to.equal(false);
  41.     });
  42.  
  43.         it('testing generateHolidayPackage without people', function() {
  44.         expect(()=> sampleInstance.generateHolidayPackage()).to.throw('There must be at least 1 vacationer added');
  45.     });
  46.  
  47.     it('testing generateHolidayPackage', function() {
  48.         sampleInstance.addVacationer('Pesho Peshov');
  49.         expect(sampleInstance.generateHolidayPackage()).to.equal(`Holiday Package Generated\nDestination: Hawaii\nVacationers:\nPesho Peshov\nPrice: 600`);
  50.     });
  51.  
  52.     it('testing generateHolidayPackage with wrong season', function() {
  53.         sampleInstance = new HolidayPackage('Hawaii','ASDASD')
  54.         sampleInstance.addVacationer('Pesho Peshov');
  55.         sampleInstance.addVacationer('Gosho Peshov');
  56.         expect(sampleInstance.generateHolidayPackage()).to.equal(`Holiday Package Generated\nDestination: Hawaii\nVacationers:\nPesho Peshov\nGosho Peshov\nPrice: 800`);
  57.     });
  58.  
  59.     it('testing showVacationers without people', function() {
  60.         expect(sampleInstance.showVacationers()).to.deep.equal("No vacationers are added yet");
  61.     });
  62.     it('testing showVacationers with two people', function() {
  63.         sampleInstance.addVacationer('Pesho Peshov');
  64.         sampleInstance.addVacationer('Gosho Peshov');
  65.         expect(sampleInstance.showVacationers()).to.deep.equal(`Vacationers:\nPesho Peshov\nGosho Peshov`);
  66.     });
  67.  
  68.     it('testing generateHolidayPackage with insurance', function() {
  69.         sampleInstance.addVacationer('Pesho Peshov');
  70.         sampleInstance.addVacationer('Gosho Peshov');
  71.         sampleInstance.insuranceIncluded = true;
  72.         expect(sampleInstance.generateHolidayPackage()).to.equal(`Holiday Package Generated\nDestination: Hawaii\nVacationers:\nPesho Peshov\nGosho Peshov\nPrice: 1100`);
  73.     });
  74.  
  75.     it('testing generateHolidayPackage with insurance and summer', function() {
  76.         sampleInstance = new HolidayPackage('Hawaii','Summer')
  77.         sampleInstance.addVacationer('Pesho Peshov');
  78.         sampleInstance.addVacationer('Gosho Peshov');
  79.         sampleInstance.insuranceIncluded = true;
  80.         expect(sampleInstance.generateHolidayPackage()).to.equal(`Holiday Package Generated\nDestination: Hawaii\nVacationers:\nPesho Peshov\nGosho Peshov\nPrice: 1100`);
  81.     });
  82. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement