0

I am using a getCookie function to access cookies in a Pinia store. When trying to test this with Vitest, I get the following error:

Error: Cookie has domain set to the public suffix "localhost" which is a special use domain. To allow this, configure your CookieJar with {allowSpecialUseDomain:true, rejectPublicSuffixes: false}.

Below is the code for the getCookie function I am using:

//https://stackoverflow.com/a/5968306/14131782
function getCookie(name: string) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  var end = 0;
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else {
    begin += 2;
    end = document.cookie.indexOf(";", begin);
    if (end == -1) {
      end = dc.length;
    }
  }

  return decodeURI(dc.substring(begin + prefix.length, end));
}

Is there some way I can configure document.cookie for testing this?

user14131782
  • 736
  • 1
  • 11
  • 20

1 Answers1

0

This was resolved by updating the tough-cookie module

user14131782
  • 736
  • 1
  • 11
  • 20