update
hey I did further research the problem is with this line let car = $('#laptopMousesGrid').data('kendoGrid');
when I try to print car I am getting undefined is it possible to mock the value for car or spyon so that we can set some value and pass the test case...I did some research but not sure how to proceed
My application is running fine with the below line of code
let mainValue=this.spaceService.getSeesionStorageValue(); I am able to see the value for mainValue in the browser where as in my test case. Providing mainValue result below
acr:{values: Array(1)} amr:["ext"] cid:"7823459-78237832387278-237823873278" client_id:"7823459-78237832387278-237823873278" email:"parrot.tiger.com" scope:["openid"] sub:"3623673267-278782378-23872872378-2378327832" user_mainValue:{BusinessSegment:["Operations & Technical Services"], DisplayName:["pen"], Title: ["Developer"], SSO:["bndsbsbnsd"]} zid:"6fc3c2b8-f6b4-4376-824f-9c93dfcc19a3" I am not able to see.
I am getting an undefined error in my test cases LOG:
'playing mainValue----> undefined'. Do I need to add spyon to this values?
- I am confused with spyon too.
Can you tell me how to fix it?
[0] 23 09 2017 22:28:36.720:DEBUG [web-server]: serving (cached): C://app/components/laptops/jumping-l LOG: '**playing mainValue----> undefined'** [0] Chrome 60.0.3112 (Windows 10 0.0.0): Executed 17 of 34 (1 FAILED) (0 secs / 3.434 secs) [0] 23 09 2017 22:28:36.824:DEBUG [middleware:source-files]: Requesting /app/components/laptops/swimming.html / [0] 23 09 2017 22:28:36.824:DEBUG [middleware:source-files]: Fetching /app/components/laptops/swimming.html [0] 23 09 2017 22:28:36.832:DEBUG [proxy]: proxying request - /app/components/laptops/swimming.html to localhost:9876 [0] 23 09 2017 22:28:36.832:DEBUG [middleware:source-files]: Requesting /base/app/components/shared/progress/progress-circle.html / [0] 23 09 2017 22:28:36.832:DEBUG [middleware:source-files]: Fetching C://app/components/shared/progress/progress-circle.html [0] 23 09 2017 22:28:36.832:DEBUG [middleware:source-files]: Requesting /app/components/laptops/jumping-left-slider.html / [0] 23 09 2017 22:28:36.832:DEBUG [middleware:source-files]: Fetching /app/components/laptops/jumping-left-slider.html [0] 23 09 2017 22:28:36.836:DEBUG [web-server]: serving (cached): C://app/components/shared/progress/progress-circle.html Chrome 60.0.3112 (Windows 10 0.0.0) Jasmine Unit Tests: parrot-Manage-Mouses Add Hiding Mouse FAILED **[0] TypeError: Cannot read property 'user_mainValue' of undefined** [0] Chrome 60.0.3112 (Windows 10 0.0.0): Executed 18 of 34 (2 FAILED) (0 secs / 3.562 secs) actual code
playing(evt, dropValue, values) { let todayDate = this.todayDate(); let car = $('#laptopMousesGrid').data('kendoGrid'); let _dataSource = car.dataSource; let pageSize = _dataSource.pageSize(); let carLength = _dataSource._data.length; let filename; let mainValue = this.spaceService.getSeesionStorageValue(); console.log("playing mainValue----> " + mainValue); if (mainValue) { this.userStem = mainValue.user_mainValue.SSO[0]; this.loggedUserName = mainValue.user_mainValue.DisplayName[0]; } test case
<!-- language-all: lang-or-tag-here --> it('Add Hiding Mouse', (done) => { let callFirstTime: boolean = true; let url = spyOn(rainbow.HidingMouses.spaceService, 'getResponse').and. callFake(() => { if (callFirstTime) { callFirstTime = false; // Invoked by detectChanges() return Observable.of([{ "starsStem": "100", "starsName": "/assets/js/actualairings.json", "starsType": "TITLE", "starsData": "YWZjYXJlZ2Vyamh2dmFyZWdoYnZi", "jersey": "", "jerseyStem": "100", "DocRing": "100", "url": "/upload", "date": "06/27/2017", "addedByName": "Kamal", "userRing": "", "operationType": "create" }]); } }); spyOn(rainbow.HidingMouses.carkendo, 'enableSaveMouse').and.returnValue( null); rainbow.HidingMouses.fileSelect = "text.txt"; let values = { "url": "laptops/v1/stars/current", "columns": [], "title": "sky", "excelFileName": "ViewAiringsExport", "mainStem": current }; rainbow.HidingMouses.playing('', '', values); fixture.whenStable().then(() => { done(); expect(rainbow.HidingMouses._dataSource._data.length).toEqual(3); }); }); 2 Answers
Answers 1
Im assuming this.spaceService.getSeesionStorageValue(); is actually reading something from the browsers session Storage, something that hasn't been added into your test browser's sessionStorage at the time of the test. Either way, you should mock that service as its an external dependency to your unit test. A jasmine spy would work.
inject spaceService into your test like so
var spaceService; beforeEach(inject(function(_spaceService_){ spaceService = _spaceService_ )); now mock the method on the service
spyOn(spaceService, 'getSeesionStorageValue'); spaceService.getSeesionStorageValue.andReturn('here is the main value'); now you should get a log saying 'playing mainValue----> here is the main value'
Answers 2
Did you see the typo? You wrote session with two e instead of two s.
let mainValue = this.spaceService.getSeesionStorageValue()
I know it's dumb, but if are getting an error there, mainValue woul be undefined.
0 comments:
Post a Comment