tomtomau / repro-localstorage-inject

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@inject LocalStorage issue

This is a reproduction of an issue I'm having specifically with:

  • jest testing of typescript components
  • @inject on the units
  • trying to inject something from lib.dom.d.ts

Refer to the components foo.ts and bar.ts as well as the corresponding jest tests.

Running yarn jest will run the tests and demonstrate:

  • foo.spec.ts will fail as Storage is not known:
 FAIL  test/unit/foo.spec.ts
  ● Test suite failed to run

    ReferenceError: Storage is not defined



      at src/foo.ts:866:105
      at Object.<anonymous> (src/foo.ts:869:2)
      at Object.<anonymous> (test/unit/foo.spec.ts:1:1)
  • bar.spec.ts will be operate properly, including executing a call onto the fake Storage that was created

The only difference here is that foo has @inject.

Note that in tsconfig.json, dom is set in the lib entry - ergo the DOM library is being included. For some reason, with Jest + @inject, this has an issue.

I have no idea what's going on here, thus casting out my net to see if anyone else can help explain/fix it.

About


Languages

Language:TypeScript 65.3%Language:JavaScript 32.9%Language:HTML 1.9%