From 8209822b641b5b5729bb954e4d26e9aa246136ac Mon Sep 17 00:00:00 2001 From: Ganesh Date: Tue, 20 Oct 2020 19:59:12 +0530 Subject: [PATCH] d2 ex --- .../unit-tests/js-3.6.0/SpecRunner.html | 10 ++++--- .../js-3.6.0/spec/ListObjFormatSpec.js | 12 ++++++++ .../unit-tests/js-3.6.0/spec/MockClockSpec.js | 28 +++++++++++++++++-- .../js-3.6.0/spec/spyjasminespec.js | 17 +++++++++++ .../unit-tests/js-3.6.0/src/spyjasmine.js | 15 ++++++++++ 5 files changed, 75 insertions(+), 7 deletions(-) create mode 100755 jasmine-async-await/unit-tests/js-3.6.0/spec/ListObjFormatSpec.js create mode 100755 jasmine-async-await/unit-tests/js-3.6.0/spec/spyjasminespec.js create mode 100755 jasmine-async-await/unit-tests/js-3.6.0/src/spyjasmine.js diff --git a/jasmine-async-await/unit-tests/js-3.6.0/SpecRunner.html b/jasmine-async-await/unit-tests/js-3.6.0/SpecRunner.html index 24d9731..d0a2ce0 100644 --- a/jasmine-async-await/unit-tests/js-3.6.0/SpecRunner.html +++ b/jasmine-async-await/unit-tests/js-3.6.0/SpecRunner.html @@ -13,15 +13,17 @@ - + + - + + diff --git a/jasmine-async-await/unit-tests/js-3.6.0/spec/ListObjFormatSpec.js b/jasmine-async-await/unit-tests/js-3.6.0/spec/ListObjFormatSpec.js new file mode 100755 index 0000000..b4eaf4d --- /dev/null +++ b/jasmine-async-await/unit-tests/js-3.6.0/spec/ListObjFormatSpec.js @@ -0,0 +1,12 @@ +it('compares some lists', function() { + const expectedListOfPersons = [ + {name: 'Tom', age:20, dob: '20/10/2000'}, + {name: 'John', age:30, dob: '20/10/1990'} + ]; + const actualListOfPersons = [ + {name: 'Thomas', age:20, dob: '20/10/2000'}, + {name: 'Johnny', age:30, dob: '20/10/1990'} + ]; + + expect(actualCells).toEqual(expectedCells); +}); diff --git a/jasmine-async-await/unit-tests/js-3.6.0/spec/MockClockSpec.js b/jasmine-async-await/unit-tests/js-3.6.0/spec/MockClockSpec.js index 64e6fd5..20e61ac 100755 --- a/jasmine-async-await/unit-tests/js-3.6.0/spec/MockClockSpec.js +++ b/jasmine-async-await/unit-tests/js-3.6.0/spec/MockClockSpec.js @@ -1,13 +1,22 @@ describe('debounced test', function(){ +function displayPerson(p){ + + var p1 = p[0]; + var p2 = p[1]; + return p1.name + ',' + p1.dob + '||' + p2.name + ',' + p2.dob; + //return '--Person name-- - ' + p.name + ',' + p.dob; +} + beforeEach(function(){ - jasmine.clock().install(); + //jasmine.clock().install(); + jasmine.addCustomObjectFormatter(displayPerson); }); afterEach(function(){ - jasmine.clock().uninstall(); + //jasmine.clock().uninstall(); }); - +/* it('should call the method only after the 500ms debounce', function(){ function debouncedMethod() { // do something async; @@ -24,4 +33,17 @@ describe('debounced test', function(){ //assertions follow }); +*/ + it('compares some lists', function() { + const expectedListOfPersons = [ + {name: 'Tom', age:20, dob: '20/10/2000'}, + {name: 'John', age:30, dob: '20/10/1990'} + ]; + const actualListOfPersons = [ + {name: 'Thomas', age:20, dob: '20/10/2000'}, + {name: 'Johnny', age:30, dob: '20/10/1990'} + ]; + + expect(actualListOfPersons).toEqual(expectedListOfPersons); + }); }); \ No newline at end of file diff --git a/jasmine-async-await/unit-tests/js-3.6.0/spec/spyjasminespec.js b/jasmine-async-await/unit-tests/js-3.6.0/spec/spyjasminespec.js new file mode 100755 index 0000000..db684b9 --- /dev/null +++ b/jasmine-async-await/unit-tests/js-3.6.0/spec/spyjasminespec.js @@ -0,0 +1,17 @@ +describe("Example Of jasmine Spy using spyOn()", function() { + + it('uses the dictionary to say "hello world"', function() { + var dictionary = new Dictionary; + var person = new Person; + + spyOn(dictionary, "hello"); // replace hello function with a spy + spyOn(dictionary, "world"); // replace world function with another spy + + person.sayHelloWorld(dictionary); + expect(dictionary.hello).toHaveBeenCalled(); + // not possible without first spy + + expect(dictionary.world).toHaveBeenCalled(); + // not possible withoutsecond spy + }); +}); \ No newline at end of file diff --git a/jasmine-async-await/unit-tests/js-3.6.0/src/spyjasmine.js b/jasmine-async-await/unit-tests/js-3.6.0/src/spyjasmine.js new file mode 100755 index 0000000..d4d8735 --- /dev/null +++ b/jasmine-async-await/unit-tests/js-3.6.0/src/spyjasmine.js @@ -0,0 +1,15 @@ +var Person = function() {}; + +Person.prototype.sayHelloWorld = function(dict) { + return dict.hello() + " " + dict.world(); +}; + +var Dictionary = function() {}; + +Dictionary.prototype.hello = function() { + return "hello"; +}; + +Dictionary.prototype.world = function() { + return "world"; +}; \ No newline at end of file