Usage with Jest - ReferenceError: chrome is not defined
See original GitHub issueI’m getting ReferenceError: chrome is not defined
when trying to use sinon-chrome
with Jest.
Can anyone help me get this working?
Issue Analytics
- State:
- Created 5 years ago
- Comments:8
Top Results From Across the Web
jest-chrome - npm
Start using jest-chrome in your project by running `npm i jest-chrome`. There are no other projects in the npm registry using jest-chrome.
Read more >Usage with Jest - ReferenceError: chrome is not defined
I'm getting ReferenceError: chrome is not defined when trying to use sinon-chrome with Jest. Can anyone help me get this working? See More....
Read more >Mocking in Jest (Typescript - Mock chrome namespace)
ReferenceError : chrome is not defined. Because one of the components calls this namespace to add a listener ( chrome.runtime.onMessage.
Read more >Jest mock referenceerror cannot access before initialization
Oct 10, 2021 · If the module you are mocking is a Node Jest uses a custom ... ReferenceError: x is not defined...
Read more >ReferenceError: "x" is not defined - JavaScript - MDN Web Docs
There is a non-existent variable referenced somewhere. This variable needs to be declared, or you need to make sure it is available in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think @marcus-sa was referring to something like this:
However, this was not my issue. My issue is that I am using
webextension-polyfill
in most of my classes for the extension project and I couldn’t test a single one, becausechrome
is not defined.Just importing the class would throw such error, without any other needs.
How I managed to fix this? - Easy.
Below all your module imports, mock the polyfill with this package.
I was getting the same error so I had to declare
window.chrome = chrome
before including my .js file to be tested.