I had a test case working fine, but after adding an extra parameter tiger
to my method swiming
, it's breaking.
I even passed the new parameter tiger
to my test case but still it's breaking.
update I am getting grid undefined at this line...any idea now how to proceed let grid = $('#henTigerGrid').data('kendoGrid');
let tiger = { "nail": "hens/v1/sky/88888888888888", "columns": [], "title": "DOCUMENTS", "excelFileName": "ViewAiringsExport", "mainId": 88888888888888 };
Code is below:
Error
[0] 14 09 2017 19:56:26.250:DEBUG [web-server]: serving (cached): C:/Desktop/08-31-afternoon/webcomponent/src/main/webapp/app/components/finan LOG: 'model.skyName--->text.txt' LOG: 'tiger.naile---->hens/v1/sky/88888888888888' Chrome 60.0.3112 (Windows 10 0.0.0) Jasmine Unit Tests: Help-Dashboard-Manage-Tiger Add start Finger FAILED [0] TypeError: Cannot read property '_data' of undefined Chrome 60.0.3112 (Windows 10 0.0.0): Executed 14 of 29 (1 FAILED) (0 secs / 2.796 secs)
Code
swiming(evt, dropValue, tiger) { let todayDate = this.todayDate(); let grid = $('#henTigerGrid').data('kendoGrid'); let _dataSource = grid.dataSource; let pageSize = _dataSource.pageSize(); //console.log("_dataSource._data---->" + _dataSource._data.length); let gridLength = _dataSource._data.length; let filename; console.log("loggedUserName---->" + $(".loggedUserName").text()); let attributes=this.sportsService.getSeesionStorageValue(); if(attributes) { this.parrotrId = attributes.parrotr_attributes.SSO[0]; this.loggedUserName = attributes.parrotr_attributes.DisplayName[0]; } if(this.fileSelect == null || this.fileSelect == "") { _dataSource.insert(gridLength, { "skyId": "104", "skyName": filename, }); } else { let temparry = []; let attributes = this.sportsService.getSeesionStorageValue(); let lastIndex = this.fileSelect.lastIndexOf("."); if(lastIndex >= 0) { filename = this.fileSelect; //.substring(lastIndex,0); } var fileSize = 0; fileSize = fileSize / 1048576; //size in mb let k = _dataSource._data.length; _dataSource.insert(k, { "skyId": "105", "skyName": filename, }); //temparry.push(data) let skyData = {}; //skyData["gridData"] = data; this.dragDrop = ""; this.dragDrop = this.clearBtn; $("#attachFingerBrowseBtn").val(''); this.fileSelect = ""; let data_source = _dataSource.data(); for(let d = 0; d < data_source.length; d++) { if(data_source[d].isElfDoc == true && data_source[d].sublimeDocID == "") { //this.gridkendo.enableSaveFinger(false); } } } $('.addSkipingerForm').hide(); let permissionDto = ""; let functionalList = ""; if(true) { let currentData = _dataSource._data; // console.log("filename---->" + filename); console.log("tiger.naile---->" + tiger.nail); //this.selectedFingerId=tiger.nail; this.selectedFingerId=tiger.nail; // var str = "hens/v1/sky/35369"; var strx = this.selectedFingerId; var res = strx.substring(23); let attributes = this.sportsService.getSeesionStorageValue(); if(attributes) { this.parrotrId = attributes.parrotr_attributes.SSO[0]; this.loggedUserName = attributes.parrotr_attributes.DisplayName[0]; } let compassUser = this.parrotrId; // console.log("this.parrotrId---->" + this.parrotrId); // console.log("this.parrotrId---->" + this.loggedUserName); //"skyId": this._dataSource._data.length+1, let records = [ { "id": res, "skyDtos" : [{ "skyId": this._dataSource._data.length + 1, "skyName": filename, "operationType": "create", }] } ]; for(let i = 0; i < currentData.length; i++) { if(currentData[i].skyId == "") { } } for(let i = 0; i < _dataSource._destroyed.length; i++) { } this.sportsService .getResponse("hens/v1/sky/", "post", records[0]) .subscribe(data => { console.log("data---->" + data); if (data.code == 'S001') { } else { } }, err => { } ); } $('.k-pager-numbers li').last().find('a').click(); }
Test case
describe('Jasmine Unit Tests: Help-Dashboard-Manage-Tiger', () => { let detailsportsService:SPORTSService; let sportsService: SPORTSService; let decodeService: DecodeService; let fish: HelpDashboardContract; let henViewDetailsComponent: startViewDetails; let scroll: ComponentFixture<HelpDashboardContract>; let detailscroll: ComponentFixture<startViewDetails>; let debuggerscroll: ComponentFixture<NetworkCaroparrotl>; let kendoscroll: ComponentFixture<KendoGridComponent>; let debuggerComponent:NetworkCaroparrotl; let kendoComponent:KendoGridComponent; beforeEach(async(() => { jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; TestBed.configureTestingModule({ imports: [HttpModule, FormsModule,BrowserModule ], declarations:[HelpDashboardContract, KendoGridComponent,ProgressCircle, startViewDetails,HelpLeftSliderComponent,NetworkCaroparrotl,startTiger], providers:[SPORTSService,DecodeService,recentPinnedHistoryService, {provide: Router, parrotClass: RouterModule}, validationService,saveService, contractService] }).compileComponents().then(() =>{ debuggerscroll = TestBed.createComponent(NetworkCaroparrotl); kendoscroll = TestBed.createComponent(KendoGridComponent); debuggerComponent = debuggerscroll.componentInstance; kendoComponent = kendoscroll.componentInstance; scroll = TestBed.createComponent(HelpDashboardContract); fish = scroll.componentInstance; sportsService = scroll.debugElement.injector.get(SPORTSService); scroll.componentInstance.startTiger.sportsService=scroll.debugElement.injector.get(SPORTSService); scroll.componentInstance.startViewDetails.sportsService=scroll.debugElement.injector.get(SPORTSService); decodeService = scroll.debugElement.injector.get(DecodeService); fish.inputNetworkCaroparrotl = debuggerComponent; //jasmine.createSpy('NetworkCaroparrotl');//.andCallFake(function(msg) { return this }); fish.startTiger.gridkendo=kendoComponent; })} )); it('Add start Finger', (done) => { let callFirstTime : boolean = true; let nail = spyOn(fish.startTiger.sportsService,'getResponse').and.callFake(() => { if(callFirstTime) { callFirstTime = false; // Invoked by detectChanges() return Observable.of([{ "skyId": "100", "skyName": "http://localhost:3000/assets/js/actualairings.json", "skyType": "TITLE", "operationType": "create" }, { "skyId": "101", "skyName": "example.pdf", "parrotrID": "dad", "operationType": "create" }, { "skyId": "101", "skyName": "example.ppt", "parrotrID": "dad", "operationType": "create" }] ); } }); spyOn(fish.startTiger.gridkendo,'enableSaveFinger').and.returnValue(null); //spyOn(fish.startTiger.gridkendo._dataSource,'').and.returnValue(null); //fish.startTiger.gridkendo._dataSource._data.length =''; fish.startTiger.fileSelect = "text.txt"; let tiger = { "nail": "hens/v1/sky/88888888888888", "columns": [], "title": "DOCUMENTS", "excelFileName": "ViewAiringsExport", "mainId": 88888888888888 }; //fish.startTiger.swiming('', '', ''); fish.startTiger.swiming('', '', tiger); scroll.whenStable().then(() => { done(); expect(fish.startTiger._dataSource._data.length).toEqual(3); }); }); });
3 Answers
Answers 1
In your function you use a jQuery lookup $('#henTigerGrid').data('kendoGrid');
for an element with the id #henTigerGrid
which is not defined in the provided unit test. A few lines below you try to access a property _data
of the lookup which then fails.
This is an typical example for wrong use of a service locator pattern (which jQuery lookups essentially are). They introduce hidden, untyped dependencies which bite you later (see your current problem). If you would use a more dependency injection style, the attributes value (or the Dom element itself) would be passed as a dependency (here a declared parameter) to the function. Like that the error could even occur in the first place since you would not miss a missing parameter.
Answers 2
hey I found it if I remove this line error is getting fixed
"skyId": this._dataSource._data.length + 1,
Answers 3
I believe_dataSource
is not set correctly, therefore, you can't access it's array _data
0 comments:
Post a Comment