I'm using cookies to pass the session about the logged in user, and on the server I can set and get them fine:
res.cookie("foo", { bar: "baz" })
// later on
console.log(req.cookies.foo) // { bar: "baz" }
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. { bar: "baz" }, to the header string the cookie evaluates to

What's the algorithm used here?
(I'm using supertest but it shouldn't matter IMO)