I use jsdom I put cookies in the test. How to correctly pick up cookies? If I do so window.document.cookie, I get only the first value

const obj = new JSDOM( `<!DOCTYPE html><body> <script> (function() { window.document.cookie = 'param1=val1;param2=val2'; })(); </script> </body>`, { contentType: "text/html", runScripts: "dangerously" } ); // only param1=val1 console.log( obj.window.document.cookie); 

  • Cookies must be set separately. - Alexey Ten

1 answer 1

Assign one pair.

 const obj = new JSDOM( `<!DOCTYPE html><body> <script> (function() { window.document.cookie = 'param1=val1'; window.document.cookie = 'param2=val2'; })(); </script> </body>`, { contentType: "text/html", runScripts: "dangerously" } ); // param1=val1; param2=val2 console.log(obj.window.document.cookie); 

Semicolon is used for other purposes - https://learn.javascript.ru/cookie