title: ReferenceError: Storage is not defined
body: <p>I am a newbie on React and am trying to learn from web resources. I found MERN full stack login code on the web. When I try to compile using <code>npm start</code>, it has no issues, however when I try to compile using <code>npm test</code> it gives error 'ReferenceError: localStorage is not defined'</p>
  
  <p>I tried to declare any variable of <code>localStorage</code> but also get a also similar error. It seems that I need to put the value somewhere but why is it giving an error on <code>npm test</code> only</p>
  
  <pre><code>  "scripts": {
      "start": "react-scripts start",
      "build": "react-scripts build",
      "test": "react-scripts test --env=jsdom",
      "eject": "react-scripts eject"
    },
  </code></pre>
  
  <pre><code>import React, { Component } from 'react'
  import { Link, withRouter } from 'react-router-dom'
  
  class Landing extends Component {
  
    logOut(e) {
      e.preventDefault()
      localStorage.removeItem('usertoken')
      this.props.history.push(`/`)
    }
  
    render() {
  
      const loginRegLink = (
        &lt;ul className="navbar-nav"&gt;
          &lt;li className="nav-item"&gt;
            &lt;Link to="/login" className="nav-link"&gt;
              Login
            &lt;/Link&gt;
          &lt;/li&gt;
          &lt;li className="nav-item"&gt;
            &lt;Link to="/register" className="nav-link"&gt;
              Register
            &lt;/Link&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      )
  
      const userLink = (
        &lt;ul className="navbar-nav"&gt;
          &lt;li className="nav-item"&gt;
            &lt;Link to="/profile" className="nav-link"&gt;
              User
            &lt;/Link&gt;
          &lt;/li&gt;
          &lt;li className="nav-item"&gt;
            &lt;a href="" onClick={this.logOut.bind(this)} className="nav-link"&gt;
              Logout
            &lt;/a&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      )
  
      return (
        &lt;nav className="navbar navbar-expand-lg navbar-dark bg-dark rounded"&gt;
          &lt;button
            className="navbar-toggler"
            type="button"
            data-toggle="collapse"
            data-target="#navbarsExample10"
            aria-controls="navbarsExample10"
            aria-expanded="false"
            aria-label="Toggle navigation"
          &gt;
            &lt;span className="navbar-toggler-icon" /&gt;
          &lt;/button&gt;
  
          &lt;div
            className="collapse navbar-collapse justify-content-md-center"
            id="navbarsExample10"
          &gt;
            &lt;ul className="navbar-nav"&gt;
              &lt;li className="nav-item"&gt;
                &lt;Link to="/" className="nav-link"&gt;
                  Home
                &lt;/Link&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
            {localStorage.usertoken ? userLink : loginRegLink}
          &lt;/div&gt;
        &lt;/nav&gt;
      )
    }
  }
  
  export default withRouter(Landing)
  </code></pre>