Advertisement
Guest User

MochaTestsSharedObj

a guest
Oct 27th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe("Test sharedObject", function () {
  2.     beforeEach("clear fields", function () {
  3.         $('#name').val('');
  4.         $('#income').val('');
  5.     });
  6.     afterEach("clear fields", function () {
  7.         $('#name').val('');
  8.         $('#income').val('');
  9.     });
  10.     describe("Test if all requred properties exist", function () {
  11.         it("should have property name", function () {
  12.             expect(sharedObject.hasOwnProperty('name')).to.be.equal(true);
  13.         });
  14.         it("should have property income", function () {
  15.             expect(sharedObject.hasOwnProperty('income')).to.be.equal(true);
  16.         });
  17.         it("should have property changeName", function () {
  18.             expect(sharedObject.hasOwnProperty('changeName')).to.be.equal(true);
  19.         });
  20.         it("should have property changeIncome", function () {
  21.             expect(sharedObject.hasOwnProperty('changeIncome')).to.be.equal(true);
  22.         });
  23.         it("should have property updateName", function () {
  24.             expect(sharedObject.hasOwnProperty('updateName')).to.be.equal(true);
  25.         });
  26.         it("should have property updateIncome", function () {
  27.             expect(sharedObject.hasOwnProperty('updateIncome')).to.be.equal(true);
  28.         });
  29.     });
  30.     describe("Test initial state", function () {
  31.         it("should equal null for sharedObject.name", function () {
  32.             expect(sharedObject.name).to.be.equal(null);
  33.         });
  34.         it("should equal null for sharedObject.income", function () {
  35.             expect(sharedObject.income).to.be.equal(null);
  36.         });
  37.         it("property changeName should be function", function () {
  38.             expect(typeof sharedObject.changeName).to.be.equal('function');
  39.         });
  40.         it("property changeIncome should be function", function () {
  41.             expect(typeof sharedObject.changeIncome).to.be.equal('function');
  42.         });
  43.         it("property updateName should be function", function () {
  44.             expect(typeof sharedObject.updateName).to.be.equal('function');
  45.         });
  46.         it("property updateIncome should be function", function () {
  47.             expect(typeof sharedObject.updateIncome).to.be.equal('function');
  48.         });
  49.     });
  50.     describe("Test nominal cases", function () {
  51.         it("should make no changes for sharedObject.changeName('')", function () {
  52.             sharedObject.changeName('');
  53.             expect(sharedObject.name).equal(null);
  54.         });
  55.         it("should make no changes for sharedObject.changeIncome('buta')", function () {
  56.             sharedObject.changeIncome('');
  57.             expect(sharedObject.income).equal(null);
  58.         });
  59.         it("should make no changes for sharedObject.changeIncome(0)", function () {
  60.             sharedObject.changeIncome(0);
  61.             expect(sharedObject.income).equal(null);
  62.         });
  63.         it("should make no changes for sharedObject.changeIncome(4.2)", function () {
  64.             sharedObject.changeIncome(4.2);
  65.             expect(sharedObject.income).equal(null);
  66.         });
  67.         it("should make no changes for sharedObject.changeIncome(-5)", function () {
  68.             sharedObject.changeIncome(-5);
  69.             expect(sharedObject.income).equal(null);
  70.         });
  71.         it("should make no changes for sharedObject.updateName() when name field is empty", function () {
  72.             sharedObject.updateName();
  73.             expect(sharedObject.name).equal(null);
  74.         });
  75.         it("should make no changes for sharedObject.updateIncome() when income field is empty", function () {
  76.             sharedObject.updateIncome();
  77.             expect(sharedObject.income).equal(null);
  78.         });
  79.         it("should make no changes for sharedObject.updateIncome() when income field is '-54'", function () {
  80.             $('#income').val('-54');
  81.             sharedObject.updateIncome();
  82.             expect(sharedObject.income).equal(null);
  83.         });
  84.         it("should make no changes for sharedObject.updateIncome() when income field is '0'", function () {
  85.             $('#income').val('0');
  86.             sharedObject.updateIncome();
  87.             expect(sharedObject.income).equal(null);
  88.         });
  89.         it("should make no changes for sharedObject.updateIncome() when income field is '4.2'", function () {
  90.             $('#income').val('4.2');
  91.             sharedObject.updateIncome();
  92.             expect(sharedObject.income).equal(null);
  93.         });
  94.     });
  95.     describe("Test normal cases", function () {
  96.         it("name property should equal 'testname' for sharedObject.changeName('testname')", function () {
  97.             sharedObject.changeName('testname');
  98.             expect(sharedObject.name).equal('testname');
  99.         });
  100.         it("name field should equal 'testname' for sharedObject.changeName('testname')", function () {
  101.             sharedObject.changeName('testname');
  102.             let nameFieldVal = $('#name').val();
  103.             expect(nameFieldVal).equal('testname');
  104.         });
  105.  
  106.         it("income property should equal 100 for sharedObject.changeIncome(100)", function () {
  107.             sharedObject.changeIncome(100);
  108.             expect(sharedObject.income).equal(100);
  109.         });
  110.         it("income field should equal '100' for sharedObject.changeIncome(100)", function () {
  111.             sharedObject.changeIncome(100);
  112.             let incomeFieldVal = Number($('#income').val());
  113.             expect(incomeFieldVal).equal(100);
  114.         });
  115.  
  116.         it("name property should equal 'testname' for sharedObject.updateName() when name field is 'testname'", function () {
  117.             $('#name').val('testname');
  118.             sharedObject.updateName();
  119.             expect(sharedObject.name).equal('testname');
  120.         });
  121.         it("income property should equal 544 for sharedObject.updateIncome() when income field is '544'", function () {
  122.             $('#income').val('544');
  123.             sharedObject.updateIncome();
  124.             expect(sharedObject.income).equal(544);
  125.         });
  126.     });
  127. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement