title: encode object into cookie string for testing
body: <p>I'm using cookies to pass the session about the logged in user, and on the server I can set and get them fine:</p>
  <pre><code>res.cookie(&quot;foo&quot;, { bar: &quot;baz&quot; })
  
  // later on
  console.log(req.cookies.foo) // { bar: &quot;baz&quot; }
  </code></pre>
  <p>Now, I want to test it, and I need to set the cookie header, but I don't know how to convert an object, i.e. <code>{ bar: &quot;baz&quot; }</code>, to the header string the cookie evaluates to
  <a href="https://i.stack.imgur.com/N6VM0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N6VM0.png" alt="enter image description here" /></a></p>
  <p>What's the algorithm used here?</p>
  <p>(I'm using supertest but it shouldn't matter IMO)</p>