Advertisement
bebo231312312321

Untitled

Jun 8th, 2023
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe('PaymentPackage', () => {
  2.   describe('valid', () => {
  3.     it('must not throw when valid', () => {
  4.       expect(() => new PaymentPackage('something', 1)).not.to.throw(Error);
  5.     });
  6.   });
  7.  
  8.   describe('name', () => {
  9.     it('must throw err when it is a number', () => {
  10.       expect(() => new PaymentPackage(5, 1)).to.throw(Error);
  11.     });
  12.  
  13.     it('must throw err when it is a an empty string', () => {
  14.       expect(() => new PaymentPackage('', 1)).to.throw(Error);
  15.     });
  16.  
  17.     it('must throw err for array and object', () => {
  18.       expect(() => new PaymentPackage([], 1)).to.throw(Error);
  19.     });
  20.   });
  21.  
  22.   describe('value', () => {
  23.     it('must throw err when it is a negative number', () => {
  24.       expect(() => new PaymentPackage('', -1)).to.throw(Error);
  25.     });
  26.  
  27.     it('must throw err when it is a string', () => {
  28.       expect(() => new PaymentPackage('something', 'test')).to.throw(Error);
  29.     });
  30.  
  31.     it('should 0 value be valid', () => {
  32.       expect(new PaymentPackage('test', 0).value).to.equal(0);
  33.     });
  34.   });
  35.  
  36.   describe('VAT', () => {
  37.     it('must be a non negative number', () => {
  38.       expect(() => (new PaymentPackage('test', 1).VAT = -1)).to.throw(Error);
  39.     });
  40.  
  41.     it('must be a number', () => {
  42.       expect(typeof new PaymentPackage('something', 1).VAT).to.equal('number');
  43.     });
  44.   });
  45.  
  46.   describe('active', () => {
  47.     it('must be boolean', () => {
  48.       expect(typeof new PaymentPackage('test', 1).active).to.equal('boolean');
  49.     });
  50.  
  51.     it('must throw an error when it is a string', () => {
  52.       expect(() => (new PaymentPackage('test', 1).active = 'mambojambo')).to.throw(Error);
  53.     });
  54.  
  55.     it('must throw an error when it s a number', () => {
  56.       expect(() => (new PaymentPackage('test', 1).active = 1)).to.throw(Error);
  57.     });
  58.   });
  59.  
  60.   describe('toString()', () => {
  61.     it('must return a string', () => {
  62.       const result = new PaymentPackage('HR Services', 1500);
  63.       expect(result.toString()).to.equal(
  64.         'Package: HR Services\n- Value (excl. VAT): 1500\n- Value (VAT 20%): 1800'
  65.       );
  66.     });
  67.  
  68.     it('appends the label "inactive" to the printed name if the package is not active', () => {
  69.       const result = new PaymentPackage('HR Services', 1500);
  70.       result.active = false;
  71.       expect(result.toString()).to.equal(
  72.         'Package: HR Services (inactive)\n- Value (excl. VAT): 1500\n- Value (VAT 20%): 1800'
  73.       );
  74.     });
  75.   });
  76. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement