title: Mock chrome.storage.local functions using Jasmine
body: <p>I have the following code in a file named <code>options.js</code>. I need to mock it using Jasmine. I need to test whether <code>chrome.storage.local.set</code> is called when <code>save</code> function is called.</p>
  
  <p>In the spec file I have the following code. But it does not call the chrome function in <code>options.js</code> file. Can someone point out the mistake?</p>
  
  <pre><code>  beforeEach(function() {
      ctrl = new OptionCtrl(scope);
      chrome: {
        storage: {
          local: {
            set: function() {
            }
          }
        }
      }
    });
  
    it('should call storage on save', function() {
      spyOn(chrome.storage.local, 'set').and.callThrough();
      ctrl.save({data: 'check'}, 'check');
      expect(chrome.storage.local.set).toHaveBeenCalled();
    });
  </code></pre>
  
  <p><strong>Update 1</strong>: save function implementation</p>
  
  <pre><code>  save(data, successMessage) {
      chrome.storage.local.set(data, (error) =&gt; {
        if (error) {
          this.status('Error Occurred. Please refresh.', 1000, 100, 'danger');
        } else {
          this.status(successMessage, 1000, 100, 'success');
        }
      });
    }
  </code></pre>
  
  <p><a href="https://github.com/ankit-m/mtw_jspm/blob/master/lib/scripts/controllers/options.js" rel="nofollow">Link to the options.js file</a> - Line: 122</p>