我的测试用例运行正常,但在我的方法tiger
中添加了额外的参数swiming
之后,它就崩溃了。
我甚至将新参数tiger
传递给我的测试用例,但它仍在破坏。
更新 我在这一行得到网格未定义...现在任何想法如何继续让grid = $('#henTigerGrid')。data('kendoGrid');
let tiger = {
"nail": "hens/v1/sky/88888888888888",
"columns": [],
"title": "DOCUMENTS",
"excelFileName": "ViewAiringsExport",
"mainId": 88888888888888
};
代码如下:
错误
[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)
代码
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();
}
测试用例
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);
});
});
});
答案 0 :(得分:2)
嘿,我发现如果我删除此行错误正在修复
"skyId": this._dataSource._data.length + 1,
答案 1 :(得分:1)
在您的函数中,您对名称为AND posts.post_type LIKE 'product%'
的元素使用jQuery查找$('#henTigerGrid').data('kendoGrid');
,该元素未在提供的单元测试中定义。在下面的几行中,您尝试访问查找的属性#henTigerGrid
,然后失败。
这是错误使用服务定位器模式的典型示例(jQuery查找基本上是这样)。它们引入了隐藏的,无类型的依赖关系,这些依赖关系稍后会引起你的注意(请参阅当前的问如果要使用更多依赖项注入样式,则属性值(或Dom元素本身)将作为依赖项(此处为声明的参数)传递给函数。就像那样,错误甚至可能首先发生,因为你不会错过一个缺失的参数。