Browse Source

d2 ex

master
Ganesh 5 years ago
parent
commit
8209822b64
5 changed files with 75 additions and 7 deletions
  1. 10
      jasmine-async-await/unit-tests/js-3.6.0/SpecRunner.html
  2. 12
      jasmine-async-await/unit-tests/js-3.6.0/spec/ListObjFormatSpec.js
  3. 28
      jasmine-async-await/unit-tests/js-3.6.0/spec/MockClockSpec.js
  4. 17
      jasmine-async-await/unit-tests/js-3.6.0/spec/spyjasminespec.js
  5. 15
      jasmine-async-await/unit-tests/js-3.6.0/src/spyjasmine.js

10
jasmine-async-await/unit-tests/js-3.6.0/SpecRunner.html

@ -13,15 +13,17 @@
<!-- include source files here... -->
<!--script src="src/Player.js"></script>
<script src="src/Song.js"></script-->
<script src="src/sample.js"></script>
<script src="src/Song.js"></script>
<script src="src/sample.js"></script-->
<script src="src/spyjasmine.js"></script>
<!-- include spec files here... -->
<!--script src="spec/SpecHelper.js"></script>
<script src="spec/PlayerSpec.js"></script-->
<!--script src="spec/sampleSpec.js"></script>
<script src="spec/PromisesAndCallbacksSpec.js"></script-->
<script src="spec/MockClockSpec.js"></script>
<script src="spec/PromisesAndCallbacksSpec.js"></script>
<script src="spec/MockClockSpec.js"></script-->
<script src="spec/spyjasminespec.js"></script>
</head>

12
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);
});

28
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);
});
});

17
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
});
});

15
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";
};
Loading…
Cancel
Save