title: TypeError: undefined is not an object when unit testing with jasmine
body: <p>I'm trying to write a unit test for a function and I'm getting an error. I'm also unsure how to test other parts of the function correctly.</p>
  
  <pre><code>private dictionaryMap (loggedIn, response) {
      const translations = this.convertToArrays(response.data.translations);
  
      this.configureMomentLocale(language);
  
      if (!loggedIn) {
          this.cachePublicDictionary(translations);
      }
  
      // not testing this part
      this.dictionary = new Dictionary({
          translationMap: Object.assign({}, this.getPublicDictionaryFromCache() || {}, translations),
      });
  
      return this.rx.Observable.of(this.dictionary);
  }
  </code></pre>
  
  <p>And my unit test so far looks like this:</p>
  
  <pre><code>describe('dictionaryMap', () =&gt; {
  
      it('calls configureMomentLocale()', () =&gt; {
          const foo = {
              'foo':'bar',
          };
          spyOn(service, 'configureMomentLocale');
          service.dictionaryMap({}, false);
          expect(service.configureMomentLocale).toHaveBeenCalled();
      });
  
  });
  </code></pre>
  
  <p>And when I run this test I get this error:</p>
  
  <blockquote>
    <p>TypeError: undefined is not an object (evaluating 'response.data.translationMap') </p>
  </blockquote>
  
  <p>Do I need to mock response.data.translations or assign the json structure? (translationMap: {'email': 'email', 'forgotPassword': 'Forgot password?'})</p>
  
  <p>Also, I'm not sure how to properly test the other parts of the function, like the if statement or returning the observable. I am new to unit testing.</p>