title: Is there a way to test whether or not something is added to localStorage?
body: <p>I am currently testing a login function where the user_id of the logged in user should be added to localStorage.
  However, i am unable to test this because of an uncaught reference error: &quot;localStorage is not defined&quot;
  Could somebody help me figure this out? Have tried 'mocking' localStorage without succes.
  Using mocha and chai for testing.</p>
  <pre><code>// Test if user_id is added to localstorage
  it('should add user_id to localstorage', (done) =&gt; {
      chai.request(app)
          .post('/login')
          .send({
              username: 'admin',
              password: '1234'
          })
          .end((err, res) =&gt; {
              expect(localStorage.getItem('user_id')).to.equal('1');
              done();
          }
          );
  }
  );
  </code></pre>