title: Unit tesing an api call using jasmine
body: <p>I am writing unit tests for my website at work and I cant seem to figure out how to test an api call.</p>
  
  <p>Lets say I want to test an api call in one of my Vue components</p>
  
  <pre><code>  api.ajax("users")
  .done((response) =&gt; {
    stores.usersStore.init(response)
  })
  </code></pre>
  
  <p><strong>usersStore.js</strong></p>
  
  <pre><code> let usersStore = {
  
    store: {
      users: []
    },
  
    get() {
      return this.store
    },
  
    set(key, value) {
      if (key) {
        this.users[key] = value
      } else {
        console.error("Key required")
      }
    },
  
    init(initObject) {
      this.store.users = initObject
    }
  
  
  }
  
  export default usersStore;
  </code></pre>
  
  <p>So the api call basically just initializes the array of users. How do I test something like this in jasmine? I tried spies, and mocking.</p>
  
  <p>Any inputs would be greatly appreciated!</p>
  
  <p>Edit --> The test I am attempting to write</p>
  
  <pre><code>  describe(" Tests", function() {
  
    var us;
  
      beforeEach(function() {
  
        us = new usersStore()
         us.store.users.push("Anand Dharne")
      });
  
      describe("when retrieved by name", function() {
        var u;
  
        beforeEach(function(done) {
          u = us.init(response, {
            success: function () {
              done();
            }
          });
        });
  
        it("api call", function() {
          expect(u.store.users).toEqual("Anand Dharne");
        });
      });
    });
  </code></pre>