rstacruz/jsdom-global

Using localStorage and sessionStorage

tomprats opened this issue · 2 comments

I just ran into an issue where a library I'm using uses sessionStorage, so I'm getting sessionStorage is not defined in my tests. Is there any plan to support these types of storages in jsdom-global?

After some research I noticed there is a PR in jsdom that's pretty related. Would jsdom-global then just need to put them in the global scope like it does document and window?

jsdom/jsdom#2076

It seems there is no way to send the required url parameter into jsdom allowing mocha tests to use localstorage. This has been a hard requirement since jsdom v11.12.0 (6 months now)

Can we get an update on this?

Edit: Minimal test case reproduction in Mocha. We should have some mechanism to set url config so the following passes:

mocha --exit --require ts-node/register --require jsdom-global/register ./app/test/*.ts

  @test public async sessionStorate() {
    try {
      if(window && window.localStorage) {
        //have storage
        assert.ok("does not break control flow");
      } else {
        //doesnt have storage
        assert.ok("does not break control flow");
      }
    } catch {
      assert.fail("breaks control flow");
    }
  }

Probably not relevant anymore with more recent versions