Advertisement
ralitsa_d

add-subtract-tests

Oct 27th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let createCalculator = require("../add-subtract").createCalculator;
  2.  
  3. let expect = require("chai").expect;
  4. describe("createCalculator()", function() {
  5.  
  6.     let calc;
  7.     beforeEach(function () {
  8.        calc = createCalculator();
  9.     });
  10.  
  11.     it("should return 0 after get()", function() {
  12.         expect(calc.get()).to.be.equal(0);
  13.     });
  14.  
  15.     it("should return 5 after {add 3; add 2}", function() {
  16.         calc.add(3);
  17.         calc.add(2);
  18.         expect(calc.get()).to.be.equal(5);
  19.     });
  20.  
  21.     it("should return -5 after {subtract 3; subtract 2}", function() {
  22.         calc.subtract(3);
  23.         calc.subtract(2);
  24.         expect(calc.get()).to.be.equal(-5);
  25.     });
  26.  
  27.     it("should return 0 after {add 3.2; subtract 3.2}", function() {
  28.         calc.add(3.2);
  29.         calc.subtract(3.2);
  30.         expect(calc.get()).to.be.equal(0);
  31.     });
  32.  
  33.     it("should return 0 after {add 3; subtract 3}", function() {
  34.         calc.add(3);
  35.         calc.subtract(3);
  36.         expect(calc.get()).to.be.equal(0);
  37.     });
  38.  
  39.     it("should return NaN after {add \"Pesho\"; subtract 3}", function() {
  40.         calc.add("Pesho");
  41.         calc.subtract(3);
  42.         expect(isNaN(calc.get())).to.be.equal(true);
  43.     });
  44.  
  45.     it("should return NaN after {subtract 'Pesho'}", function() {
  46.         calc.subtract('Pesho');
  47.         expect(isNaN(calc.get())).to.be.equal(true);
  48.     });
  49.  
  50.     it("should return 0 after {add 1; subtract 1, add -1, subtract -1}", function() {
  51.         calc.add(1);
  52.         calc.subtract(1);
  53.         calc.add('-1');
  54.         calc.subtract('-1');
  55.         expect(calc.get()).to.be.equal(0);
  56.     });
  57. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement