添加新参数后发生错误

时间:2023-01-18 23:25:24

I had a test case working fine, but after adding an extra parameter tiger to my method swiming, it's breaking.

我有一个测试用例工作正常,但在我的方法swiming中添加一个额外的参数tiger后,它正在破坏。

I even passed the new parameter tiger to my test case but still it's breaking.

我甚至将新参数tiger传递给我的测试用例,但它仍在破坏。

update I am getting grid undefined at this line...any idea now how to proceed let grid = $('#henTigerGrid').data('kendoGrid');

更新我在这一行得到网格未定义...现在任何想法如何继续让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);
        });
    });
});

2 个解决方案

#1


2  

hey I found it if I remove this line error is getting fixed

嘿,我发现它,如果我删除此行错误得到修复

                "skyId": this._dataSource._data.length + 1,

#2


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.

在你的函数中,你使用jQuery lookup $('#henTigerGrid')。data('kendoGrid');对于具有id #henTigerGrid的元素,该元素未在提供的单元测试中定义。在下面的几行中,您尝试访问查找的属性_data,然后失败。

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.

这是错误使用服务定位器模式(jQuery查找基本上是这样)的典型示例。它们引入了隐藏的,无类型的依赖关系,这些依赖关系稍后会引起你的兴趣(请参阅当前的问如果您将使用更多依赖项注入样式,那么属性值(或Dom元素本身)将作为依赖项(此处为声明的参数)传递给函数。就像那样,错误甚至可能首先发生,因为你不会错过一个缺失的参数。

#1


2  

hey I found it if I remove this line error is getting fixed

嘿,我发现它,如果我删除此行错误得到修复

                "skyId": this._dataSource._data.length + 1,

#2


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.

在你的函数中,你使用jQuery lookup $('#henTigerGrid')。data('kendoGrid');对于具有id #henTigerGrid的元素,该元素未在提供的单元测试中定义。在下面的几行中,您尝试访问查找的属性_data,然后失败。

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.

这是错误使用服务定位器模式(jQuery查找基本上是这样)的典型示例。它们引入了隐藏的,无类型的依赖关系,这些依赖关系稍后会引起你的兴趣(请参阅当前的问如果您将使用更多依赖项注入样式,那么属性值(或Dom元素本身)将作为依赖项(此处为声明的参数)传递给函数。就像那样,错误甚至可能首先发生,因为你不会错过一个缺失的参数。