title: TypeError: Cannot read property '0' of undefined. jasmine
body: <ul>
  <li>I am new to js and jasmine</li>
  <li>I am trying to right a jasmine test case for my method.</li>
  <li>But I am facing an error: <code>TypeError: Cannot read property '0' of undefined.</code></li>
  <li>I tried various ways of passing array into my method sports but still I am getting same error. Can you guys tell me how to fix it?</li>
  </ul>
  
  <p>The test</p>
  
  <pre><code>it('Read player hiking', (done) =&gt; {
      let callFirstTime : boolean = true;
      let url=
  
      spyOn(swimming.playerhikings.movieService,'getResponse').and.
          callFake(() =&gt; { 
                  if(callFirstTime){
                      callFirstTime = false; // Invoked by detectChanges() 
                      return Observable.of([{
                          "hikingId": "100",
                          "hikingName": "http://localhost:3000/assets/js/actualairings.json",
                          "hikingType": "TITLE",
                          "hikingData": "YWZjYXJlZ2Vyamh2dmFyZWdoYnZi",
                          "notes": "",
                          "notesId": "100",
                          "elfDocID": "100",
                          "url": "http://localhost:3000/upload",
                          "date": "06/27/2017",
                          "addedByName": "Kamal",
                          "userID": "206509786",
                          "operationType": "create"
                        }, {
                          "hikingId": "101",
                          "hikingName": "uploadTest4.txt",
                          "hikingType": "TITLE",
                          "hikingData": "Manish",
                          "notes": "",
                          "notesId": "101",
                          "elfDocID": "101",
                          "url": "http://localhost:3000/upload",
                          "date": "06/27/2017",
                          "addedByName": "Kamal",
                          "userID": "206509786",
                          "operationType": "create"
                        }]
                  );
                  }
           });
  
           //const args = ['p0', 'p1', 'p2'];
          //call_me.apply(this, args);
  
           var fruits = ['Apple', 'Banana'];
           var fruits1 = {"test": "1"};
  
            //console.log("swimming.playerhikings----&gt;" + 
            //      JSON.stringify(swimming.playerhikings.sports.apply(this, args)));
  
           //spyOn(swimming.playerhikings.gridkendo,'enableSavehiking').and.returnValue(null);
           //swimming.playerhikings.fileSelect = "text.txt";
           //swimming.playerhikings.sports(fruits[0]);
          swimming.playerhikings.sports(fruits1.test);
  
           //swimming.playerhikings.coffee( {0: File, length: 1});
           //console.log("swimming.playerhikings._dataSource._data.length----&gt;" + swimming.playerhikings._dataSource._data.length);
           fixture.whenStable().then(() =&gt; {
         done();
         //expect(swimming.playerhikings._dataSource._data.length).toEqual(3);
      });
  
  });
  </code></pre>
  
  <p>The code</p>
  
  <pre><code>sports(inputValue: any): void {
    var that = this;
    var file: File = inputValue.files[0];
  
    var myReader: FileReader = new FileReader();
    myReader.onloadend = (e) =&gt; {
      this.encodeBase64 = myReader.result;
      that.fileSelect = $("#attachhikingBrowseBtn").val().replace(/^.*\\/, "");
      if (that.fileSelect == '') {
        that.dragDrop = that.clearBtn;
      } else {
        that.dragDrop = "";
        that.dragDrop = that.fileSelect;
      }
    }
    $('.addELFhikingForm').show();
    if (inputValue.files.length &gt; 0) {
      var fileSize = 0;
  
      fileSize = inputValue.files[0].size / 1048576; //size in mb 
  
      if (fileSize &gt; 5) {
        alert("The hiking size exceeds the max limit of 5 MB");
  
        //confirm("The hiking size exceeds the max limit of 5 MB");
  
      }
      myReader.readAsDataURL(file);
    }
  }
  </code></pre>