2017-09-24 17 views
1

updated2はTypeError:未定義

hey, 



I moved the grid value in a new mthod carSource so the previous error I removed but right now I am getting another error, 
    - is there any way I can spy on _dataSource or mock the value to pass the test cases. 

    can you tell me how to fix it 

**TypeError: Cannot read property 'length' of undefined** 

更新されたコードのプロパティ 'user_mainValue' を読み取ることができません

public carSource():any{ 
     let car = $('#laptopMousesGrid').data('kendoGrid'); 
     return grid.dataSource; 
    } 

    playing(evt, dropValue, values) { 
     let todayDate = this.todayDate(); 
     //et car = $('#laptopMousesGrid').data('kendoGrid'); 
     //let _dataSource = car.dataSource; 

      let _dataSource =this.carSource(); 

     let pageSize = _dataSource.pageSize(); 
     if(_dataSource) { 

     console.log("playing--->"); 
     console.log("_dataSource--->" + JSON.stringify(_dataSource)); 
     console.log("_dataSource._data--->" + _dataSource._data); 

     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]; 
     } 
    } 

出力 LOG: '> ---遊ん' LOG: '、' carsID ': "100"、 "carsName": "uuiiuui"、 "carsType": "TITLE"、 "carsData": "YWZjYXJlZ2V" _dataSource ---> {"_ isScalar" "notes": "100"、 "fish": "100"、 "url": "ioioioioioi"、 "date": "ioioi"、 "addedByName": "Kamal" "carsID": "create" "、" carsId ":" 101 "、" carsName ":" example.pdf "、" carsType ":" TITLE "、" carsData ":" john ":" 6765676565 " "101"、 "fish": "101"、 "url": "ioioioioioii"、 "date": "ioioi"、 "addedByName": "Kamal"、 " "carsID": "101"、 "carsName": "example.ppt"、 "carsType": "TITLE"、 "carsData": "john" "101"、 "fish": "101"、 "url": "ioioioioioii"、 "date": "ioioi"、 "addedByName": "Kamal"、 "userID" ":" 6765676565 "、" operationType ":" create "}]、" scheduler ":null} ' ログ:' _dataSource._data ---> undefined ' Chrome 61.0.3163(Windows 10 0.0.0)ジャスミンユニットテスト:追加FAILED [0] TypeError:未定義のプロパティ 'length'を読み取ることができません Chrome 61.0.3163(Windows 10 0.0.0):69のうちの1つ(1 FAILED)(スキップされました) 68)ERROR(0.56秒/ 0.422秒)

更新

ちょっと私にはさらなる研究なかった問題は、聞かせてこのラインである車= $( '#のlaptopMousesGrid')。データ( 'kendoGrid') ;

車を印刷しようとすると私は未定義になります車やスパインの値を模擬して値を設定してテストケースを渡すことが可能です...私はいくつかの調査を行いましたが、

進む私のアプリケーションは、私は私のテストケースのようにどこブラウザでmainValueの値を見ることができる午前コード

let mainValue=this.spaceService.getSeesionStorageValue(); 

の下の行と罰金実行されています。以下のmainValue結果を提供する

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" 

私は見ることができません。

私は私のテストケースでは、未定義のエラーがログ取得しています:

'playing mainValue----> undefined'. 

私は、この値にspyonを追加する必要がありますか?

  • 私もspyonと混同しています。

修正方法を教えてもらえますか?

[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) 

実際のコード

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]; 
    } 

<!-- 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); 
    }); 
}); 
+0

'console.log(" mainValue ----> "+ mainValue);'結果を質問に追加してください。 –

+0

@MohammadJavadSeyyedi jheyはブラウザからmainValueを更新しましたが、テストケースで定義されていません...端末で実行すると –

+0

あなたは私たちに示したことが 'this.spaceService.getSeesionStorageValue()'の結果であると言いますか?どのようにして1つのlienが同じ結果が未定義であるのか、ブラウザーで見ると、this.spaceService.getSeesionStorageValue()の結果は私たちを混乱させます。問題はその方法からでなければなりません。質問にコードを追加することはできますか?これは意図されているのか、それともすべてが荒廃しているだけの誤植ですか? 'getSeesionStorageValue'? Sessionの代わりにSeesion? –

答えて

0

Imは実際BRから何かを読んでいるthis.spaceService.getSeesionStorageValue();を想定したテストケースowsers sessionストレージ。テスト時にテストブラウザのsessionStorageに追加されていないもの。いずれにせよ、あなたはそのサービスをあなたの単体テストに対する外部依存として嘲笑すべきです。ジャスミンのスパイが働くだろう。そう

var spaceService; 
beforeEach(inject(function(_spaceService_){ 
spaceService = _spaceService_ 
)); 

のようなあなたのテストに

ジェクトspaceServiceは現在、サービス

spyOn(spaceService, 'getSeesionStorageValue'); 
spaceService.getSeesionStorageValue.andReturn('here is the main value'); 

上の方法を模擬今は'playing mainValue----> here is the main value'

+0

あなたの返信に感謝...私はなぜbeforeEachを使用しているので、将来他の問題が発生した場合には、自分で修正することができます。 –

+0

サービスは各テストの前にインスタンス化されていますので、前もってどの状態でも再初期化されます – Bowofola

+0

と注入の利点注射なしで達成する?? –

0

を言ってログを取得する必要がありますが、タイプミスを見ましたか?あなたは2つのsの代わりに2つのeでセッションを書きました。

let mainValue = this.spaceService.getSeesionStorageValue()

私はそれがダムだ知っているが、そこにエラーを取得している場合、mainValueundefinedことwoul。

+0

関数が存在しない場合、getSeesionStorageVaueは関数ではありません – Bowofola

+0

heyコードベースで以下のコードを更新すると、次のエラーが発生します。それを修正する方法を教えてください。下に自分のコードとエラーを提供する------> let spaceService; beforeEach(inject(function(_spaceService_、 ''){ spaceService = _spaceService_ )); –

+0

'(_spaceService_:any)=> anyの型の引数は –

0

_dataSource._dataが_dataSourceの出力から定義されているように見えません。希望が助けてくれる!

+0

に割り当てられませんあなたの返信ありがとうございます...私のコードで更新できますか...それを修正する方法がわかりません –

関連する問題